gridExtra – Multiple plots from ggplot2

June 8, 2011

(This article was first published on Matt's Stats n stuff » R, and kindly contributed to R-bloggers)

Thanks to this great post we can now put multiple plots on a display with ggplot2. This provides somewhat similar functionality to ‘par(mfrow=c(x,y))’ which would allow multiple plots with the base plot function. gridExtra doesn’t have quite the same level of options as ‘par’, but the syntax is simple.

grid.arrange( graph1, graph2, ncol=2

Simple. ‘grid.table’ is worth checking out as well.

NOTE: Saving

I normally use ‘ggsave(…)’ to save my plots created with ggplot2. This (as yet) doesn’t work with using grid.arrange. A work around is to use a more tradition/base approach:

grid.arrange( graph1, graph2, ncol=2)


Package available here:

To leave a comment for the author, please follow the link and comment on their blog: Matt's Stats n stuff » R. offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , ,

Comments are closed.