In base graphics I can create a 4 panel pane of graphics by doing the following:
par(mfrow=c(2,2))
for (i in 1:4){
plot(density(rnorm(100)))
}
which results in
I'd like to do the same sort of thing with ggplot2, but I can't figure out how to do it. I can't use facets because my real data, unlike this trivial example, is in very different structures and I want two graphs to be point charts and two to be histograms. How can do create panels or panes in ggplot2?
Following Josh O'Brien's example: I'm surprised no one has mentioned grid.arrange
from the gridExtra
package yet:
library(gridExtra)
grid.arrange(q1,q2,q3,q4,q5,q6,nrow=3)
This seems to be mentioned here: multiple graphs in one canvas using ggplot2
For me, it's much easier than remembering all the viewport stuff.