grid.arrange的帮助文字说:
Arguments:
...: plots of class ggplot2, trellis, or grobs, and valid
arguments to grid.layout
所以阅读grid.layout会导致:
Arguments:
nrow: An integer describing the number of rows in the layout.
ncol: An integer describing the number of columns in the layout.
widths: A numeric vector or unit object describing the widths of the
columns in the layout.
heights: A numeric vector or unit object describing the heights of the
rows in the layout.
换句话说,您可以将宽度和高度作为向量传递。 grid.arrange(p1, p2, heights=c(1, 2)。或者举个例子:
dat <- data.frame(x=1:10, y=10:1)
q1 <- qplot(x, y, data=dat)
q2 <- qplot(y, x, data=dat)
q3 <- qplot(x, y, data=dat, geom='line')
q4 <- qplot(y, x, data=dat, geom='line')
grid.arrange(q1, q2, q3, q4, heights=1:2, widths=1:2)
还值得一提的是,通常可以使用reshape2 包中的melt 和ggplot2 中的facet_wrap 或facet_grid 来实现类似的效果。