Skip to content

Instantly share code, notes, and snippets.

@mplourde
Created May 30, 2014 18:24
Show Gist options
  • Save mplourde/66322522df1001f218dd to your computer and use it in GitHub Desktop.
Save mplourde/66322522df1001f218dd to your computer and use it in GitHub Desktop.
plotting multiple ggplots in one window
library(grid)
plot1 <- ggplot(data.frame(x=1:10, y=1:10), aes(x=x, y=y)) + geom_point()
plot2 <- plot1
plot3 <- plot1
nrow <- 1
ncol <- 3
vp <- viewport(layout=grid.layout(nrow, ncol))
grid.newpage()
pushViewport(vp)
print(plot1, vp=viewport(layout.pos.row=1, layout.pos.col=1))
print(plot1, vp=viewport(layout.pos.row=1, layout.pos.col=2))
print(plot1, vp=viewport(layout.pos.row=1, layout.pos.col=3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment