代码之家  ›  专栏  ›  技术社区  ›  tenticon

使用grid.arrange时如何减少ggplot和下一个文本之间的空间?

  •  1
  • tenticon  · 技术社区  · 6 年前

    考虑以下R标记页

    ```{r setup, include=FALSE}
    require(ggplot2)
    require(data.table)
    require(gridExtra)
    require(knitr)
    
    knitr::opts_chunk$set(echo = TRUE)
    ```
    
    ```{r, include=FALSE}
    df <- data.table(x1=rnorm(n = 100), x2=rnorm(100))
    ```
    
    Here is a plot
    
    ```{r,echo=FALSE, out.width='\\textwidth'}
    hist1 <- ggplot(df, aes(x=x1)) +
      geom_histogram()
    
    hist2 <- ggplot(df, aes(x=x2)) +
      geom_histogram()
    
    grid.arrange(hist1, hist2, ncol=2, heights=c(10,10))
    ```
    
    Some more text....
    

    当我绘制两个柱状图时 hist1 hist2 具有 grid.arrange() gridExtra 包我发现图太大了,我想降低高度。

    这个 heights 中的参数 网格。排列() 会降低高度,但在绘图和下一个文本之间会留下一些空白。
    我怎样才能在没有空白的情况下降低高度呢?

    1 回复  |  直到 6 年前
        1
  •  1
  •   jay.sf    6 年前