Multiple ggplots of different sizes

ggplot2, gridextra, gtable, layout, r

Solution

I appreciate all the other answers, but Didzis Elferts's comment on the OP connected to the answer that I found easiest to implement.

library(ggplot2)
p1 <- qplot(x=wt,y=mpg,geom="point",main="Scatterplot of wt vs. mpg", data=mtcars)
p2 <- qplot(x=wt,y=disp,geom="point",main="Scatterplot of wt vs disp", data=mtcars)
p3 <- qplot(wt,data=mtcars)
p4 <- qplot(wt,mpg,data=mtcars,geom="boxplot")
p5 <- qplot(wt,data=mtcars)
p6 <- qplot(mpg,data=mtcars)
p7 <- qplot(disp,data=mtcars)
p8 <- qplot(disp, y=..density.., geom="density", data=mtcars)
p9 <- qplot(mpg, y=..density.., geom="density", data=mtcars)

vplayout <- function(x, y) viewport(layout.pos.row = x, layout.pos.col = y)

grid.newpage()
pushViewport(viewport(layout = grid.layout(3, 5))) # 3 rows, 5 columns
print(p1, vp = vplayout(1:2, 1:3))  # the big plot covers rows 1:2 and cols 1:3
print(p2, vp = vplayout(1, 4))
print(p3, vp = vplayout(1, 5))
print(p4, vp = vplayout(2, 4))
print(p5, vp = vplayout(2, 5))
print(p6, vp = vplayout(3, 1))
print(p7, vp = vplayout(3, 2))
print(p8, vp = vplayout(3, 3))
print(p9, vp = vplayout(3, 4:5))

Problem

It's relatively simple using `grid.arrange` in the `gridExtra` package to arrange multiple plots in a matrix, but how can you arrange plots (the ones I'm working on are from `ggplot2`) when some plots are intended to be larger than others? In base, I can use `layout()` such as in the example below: ``` nf <- layout(matrix(c(1,1,1,2,3,1,1,1,4,5,6,7,8,9,9), byrow=TRUE, nrow=3)) layout.show(nf) ``` what is the equivalent for `ggplot` plots? Some plots for inclusion ``` library(ggplot2) p1 <- qplot(x=wt,y=mpg,geom="point",main="Scatterplot of wt vs. mpg", data=mtcars) p2 <- qplot(x=wt,y=disp,geom="point",main="Scatterplot of wt vs disp", data=mtcars) p3 <- qplot(wt,data=mtcars) p4 <- qplot(wt,mpg,data=mtcars,geom="boxplot") p5 <- qplot(wt,data=mtcars) p6 <- qplot(mpg,data=mtcars) p7 <- qplot(disp,data=mtcars) p8 <- qplot(disp, y=..density.., geom="density", data=mtcars) p9 <- qplot(mpg, y=..density.., geom="density", data=mtcars) ```

Original source

Related problems