Juliet Hannah
2009-Mar-02 18:35 UTC
[R] ways to put multiple graphs on single page (using ggplot2)
Hi, Here are three plots: library(ggplot2) data(diamonds) randind <- sample(nrow(diamonds),1000,replace=FALSE) dsmall <- diamonds[randind,] qplot(carat, data=dsmall, geom="histogram",binwidth=1) qplot(carat, data=dsmall, geom="histogram",binwidth=.1) qplot(carat, data=dsmall, geom="histogram",binwidth=.01) What are ways to put these three plots on a single page and label them A, B, and C. In general, do you use R directly for these tasks, or do you use an image editor? If you use an editor, which one do you use? I'm working on Windows. Thanks for your time. Regards, Juliet
hadley wickham
2009-Mar-02 18:48 UTC
[R] ways to put multiple graphs on single page (using ggplot2)
Hi Juliet, Have a look at the last section in http://had.co.nz/ggplot2/book/polishing.pdf Hadley On Mon, Mar 2, 2009 at 12:35 PM, Juliet Hannah <juliet.hannah at gmail.com> wrote:> Hi, Here are three plots: > > library(ggplot2) > data(diamonds) > randind <- sample(nrow(diamonds),1000,replace=FALSE) > dsmall <- diamonds[randind,] > > qplot(carat, data=dsmall, geom="histogram",binwidth=1) > qplot(carat, data=dsmall, geom="histogram",binwidth=.1) > qplot(carat, data=dsmall, geom="histogram",binwidth=.01) > > What are ways to put these three plots on a single page and label them > A, B, and C. > > In general, do you use R directly for these tasks, or do you use an > image editor? If you use an editor, which one do you use? > I'm working on Windows. Thanks for your time. > > Regards, > > Juliet > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- http://had.co.nz/
Dieter Menne
2009-Mar-02 19:04 UTC
[R] ways to put multiple graphs on single page (using ggplot2)
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()
Avram Aelony
2009-Mar-02 19:56 UTC
[R] ways to put multiple graphs on single page (using ggplot2)
I usually have a function like this: vplayout <- function(x, y) viewport(layout.pos.row=x, layout.pos.col=y) draw4 <- function(pngname, a,b,c,d,w,h) { png(pngname,width=w, height=h) grid.newpage() pushViewport(viewport(layout=grid.layout(2,2) ) ) print(a, vp=vplayout(1,1)) print(b, vp=vplayout(1,2)) print(c, vp=vplayout(2,1)) print(d, vp=vplayout(2,2)) dev.off() } #then call it with your graph objects draw4( "test.png", a,b,c,d, width, height) -Avram On Monday, March 02, 2009, at 11:04AM, "Dieter Menne" <dieter.menne at menne-biomed.de> wrote:>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() > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. > >