[R] ways to put multiple graphs on single page (using ggplot2)

Dieter Menne dieter.menne at menne-biomed.de
Mon Mar 2 20:04:20 CET 2009


Juliet Hannah <juliet.hannah <at> gmail.com> writes:

> 
> Hi, Here are three plots:
> 
(How to layout on one page)

library(ggplot2)
data(diamonds)
randind <- sample(nrow(diamonds),1000,replace=FALSE)
dsmall <- diamonds[randind,]

a= qplot(carat, data=dsmall, geom="histogram",binwidth=1)
b= qplot(carat, data=dsmall, geom="histogram",binwidth=.1)
c=qplot(carat, data=dsmall, geom="histogram",binwidth=.01)
 
## Stolen from ggplot documenation

pdf("polishing-layout.pdf", width = 8, height = 6)
grid.newpage()
pushViewport(viewport(layout = grid.layout(2, 2)))
vplayout <- function(x, y)
viewport(layout.pos.row = x, layout.pos.col = y)
print(a, vp = vplayout(1, 1:2))
print(b, vp = vplayout(2, 1))
print(c, vp = vplayout(2, 2))
dev.off()




More information about the R-help mailing list