[R] how to save multiple plots in one PDF file?

2010-05-17 Thread Shirley Bao
I have created separate plots in multiple graphics windows using the windows() function in R. How do I save all the plots in one PDF file? I tried savePlot(C:/rplot.pdf, type = pdf). However, it only saved the plot in the current graphics window. Thank you! [[alternative HTML version

Re: [R] how to save multiple plots in one PDF file?

2010-05-17 Thread Jun Shen
1.Open pdf device pdf() 2.Do your plotting as many as you want, you won't see the plots on the screen because they go directly to the pdf() device. 3.Turn off the pdf() dev.off() Then you can review your plots in the pdf file. For more details see ?pdf Jun On Mon, May 17, 2010 at 2:41 PM,

Re: [R] how to save multiple plots in one PDF file?

2010-05-17 Thread Shirley Bao
Thanks! I got an error message when opening the pdf file: There was an error opening this document. This file cannot be opened because it has no pages. Here is what I did in plotting and saving the file: pdf(file=C:/figure.pdf) for (j in 1:numColumns) { windows(width=5, height=5) plot(xj,y) }

Re: [R] how to save multiple plots in one PDF file?

2010-05-17 Thread Jun Shen
If you do plotting in a loop, then you need to print it to the device. print(plot(xj,y)) On Mon, May 17, 2010 at 3:02 PM, Shirley Bao baoxi...@gmail.com wrote: Thanks! I got an error message when opening the pdf file: There was an error opening this document. This file cannot be opened

Re: [R] how to save multiple plots in one PDF file?

2010-05-17 Thread baptiste auguie
No, that's only true for lattice and ggplot2 graphics. The problem here is with this line, windows(width=5, height=5) which shouldn't be there. HTH, baptiste On 17 May 2010 22:23, Jun Shen jun.shen...@gmail.com wrote: If you do plotting in a loop, then you need to print it to the device.

Re: [R] how to save multiple plots in one PDF file?

2010-05-17 Thread Anthony Lopez
one way: x - rnorm(100) y - x+rnorm(100) par(mfrow=c(2,2)) # this sets up the graphics window to expect a 2x2 layout plot(x,y) boxplot(x,y,names=c(var1,var2)) hist(x) hist(y) mtext(fourplots on same page,side=3,outer=T,line=-1.5) and you can adjust as needed to put more or less plots on the

Re: [R] how to save multiple plots in one PDF file?

2010-05-17 Thread Jun Shen
Thanks for pointing that out, baptiste. No need to use windows(). Width and height should be specified in pdf(). On Mon, May 17, 2010 at 3:28 PM, baptiste auguie baptiste.aug...@googlemail.com wrote: No, that's only true for lattice and ggplot2 graphics. The problem here is with this line,