我怎样才能获得ggplots的"不平衡"网格?

use*_*706 93 r ggplot2 r-grid

随着grid.arrange我可以安排多个ggplot在网格中人物使用类似,实现了多屏图:

library(ggplot2)
library(grid)
library(gridExtra)
Run Code Online (Sandbox Code Playgroud)

然后生成一些ggplot2图

plot5 <- grid.arrange(plot4, plot1, heights=c(3/4, 1/4), ncol=1, nrow=2)
Run Code Online (Sandbox Code Playgroud)

如何获得"不平衡"2 col布局,其中第一个col中有一个绘图,第二个col中有三个绘图?我玩弄了一个'网格网格'方法,试图用grid.arrange一个网格(例如plot5,上面)绘制另一个图,但得到了:

在ArrangeGrob中出错(...,as.table = as.table,clip = clip,main = main,:输入必须是grobs!

更新:

感谢您的建议.我会考虑viewportsgrid.与此同时,感谢@​​DWin,layOut'wq'包中的函数非常适合我Sweave文档中的编译图: 在此输入图像描述

更新2:

arrangeGrob命令(由@baptiste建议)也运行良好,看起来非常直观 - 至少很容易改变两列的宽度.它还具有不需要`wq'包的好处.

这是我的Sweave文件中的代码:

<<label=fig5plot, echo=F, results=hide>>=
plot5<-grid.arrange(plot4, arrangeGrob(plot1, plot2, plot3, ncol=1), 
                    ncol=2, widths=c(1,1.2))
@
\begin{figure}[]
    \begin{center}
<<label=fig5,fig=TRUE,echo=T, width=10,height=12>>=
<<fig5plot>>
@
\end{center}
\caption{Combined plots using the `arrangeGrob' command.}
\label{fig:five}
\end{figure}
Run Code Online (Sandbox Code Playgroud)

产生以下输出: 在此输入图像描述

顺便说一下,有人告诉我为什么出现'> NA'?

bap*_*ste 70

grid.arrange直接在设备上绘制; 如果你想将它与你需要的其他网格对象结合起来arrangeGrob,就像在

 p = rectGrob()
 grid.arrange(p, arrangeGrob(p,p,p, heights=c(3/4, 1/4, 1/4), ncol=1),
              ncol=2)
Run Code Online (Sandbox Code Playgroud)

编辑(07/2015):使用v> 2.0.0,您可以使用layout_matrix参数,

 grid.arrange(p,p,p,p, layout_matrix = cbind(c(1,1,1), c(2,3,4)))
Run Code Online (Sandbox Code Playgroud)

  • 你能解释一下```cbind(c(1,1,1),c(2,3,4))``矩阵如何描述数字的排列? (6认同)
  • @RonGejman如果你在屏幕上打印3x2矩阵很容易:第一列全部为1,这是第一个绘图所在的位置,跨越三行; 第二列包含图2,3,4,每列占据一行. (5认同)

42-*_*42- 17

我尝试用网格计算它,并认为我把它弄下来但最终失败了(虽然现在看看我在下面引用的函数中的代码,我可以看到我真的很接近...... :-)

'wq'包有一个layOut可以为你做的功能:

p1 <- qplot(mpg, wt, data=mtcars)
layOut(list(p1, 1:3, 1),   # takes three rows and the first column
        list(p1, 1, 2),    # next three are on separate rows
         list(p1, 2,2), 
          list(p1, 3,2))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • @joran:我做到了.我不记得哪个"编程的三个优点"是懒惰,但我知道那是某个地方. (3认同)