Last active
August 29, 2015 13:58
-
-
Save Buttonwood/10015520 to your computer and use it in GitHub Desktop.
R multiplot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(gridExtra) | |
a <- qplot(TMPRSS4, ECADHERIN, data=spear) | |
b <- qplot(TMPRSS4, ECADHERIN, data=spear, geom="jitter") | |
grid.arrange(a,b,ncol=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can refer to http://www.anaharb.com/2014/0228/R-grid-n-into-1/