gridExtra – Multiple plots from ggplot2

[This article was first published on Matt's Stats n stuff » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Thanks to this great post http://www.imachordata.com/?p=730 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:

pdf("filename.pdf") grid.arrange( graph1, graph2, ncol=2) dev.off()

Enjoy!

Package available here: http://cran.r-project.org/web/packages/gridExtra/


To leave a comment for the author, please follow the link and comment on their blog: Matt's Stats n stuff » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)