Skip to content

Instantly share code, notes, and snippets.

@Buttonwood
Last active August 29, 2015 13:58
Show Gist options
  • Save Buttonwood/10015520 to your computer and use it in GitHub Desktop.
Save Buttonwood/10015520 to your computer and use it in GitHub Desktop.
R multiplot
library(gridExtra)
a <- qplot(TMPRSS4, ECADHERIN, data=spear)
b <- qplot(TMPRSS4, ECADHERIN, data=spear, geom="jitter")
grid.arrange(a,b,ncol=2)
library(ggplot2)
library(grid)
#generate a new page, or erase the current one.
grid.newpage()
#maintain a Viewport tree, which describe the regions and coordinate systems.
pushViewport(viewport(layout=grid.layout(1,2)))
#generate two ggplot2 objects.
a <- qplot(TMPRSS4, ECADHERIN, data=spear)
b <- qplot(TMPRSS4, ECADHERIN, data=spear, geom="jitter")
#print them into the Viewport, or the page.
print(a, vp=viewport(layout.pos.row=1,layout.pos.col=1))
print(b, vp=viewport(layout.pos.row=1,layout.pos.col=2))
#also, you can define a function to make the print process more concise.
@Buttonwood
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment