With grid.arrange
我可以安排多个ggplot
通过使用类似以下内容的网格中的图形来实现多面板图形:
library(ggplot2)
library(grid)
library(gridExtra)
生成一些 ggplot2 图,然后
plot5 <- grid.arrange(plot4, plot1, heights=c(3/4, 1/4), ncol=1, nrow=2)
如何获得“不平衡”的 2 列布局,整个第一列中有一个图,第二列中有三个图?
我尝试使用“网格网格”方法grid.arrange
绘制一个网格(例如plot5
,上面)针对另一个情节,但获得:
arrayGrob(..., as.table = as.table, Clip = Clip, main = main, 中的错误:
输入必须是grob!
Update:
Thanks for the advice. I will look into viewports
and grid
. In the meantime, thanks to @DWin, the layOut
function in the 'wq' package worked very well for the compilation figure in my Sweave
document:
![enter image description here](https://i.stack.imgur.com/ECZdb.png)
更新2:
The 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}
which produces the following output:
![enter image description here](https://i.stack.imgur.com/043sb.png)
顺便说一句,有人告诉我为什么会出现“>NA”吗?