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

baptiste auguie baptiste.auguie at googlemail.com
Mon May 17 22:28:20 CEST 2010


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.ut at gmail.com> wrote:
> 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 <baoxinli at 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 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)
>> }
>> dev.off()
>>
>> Any ideas what might cause the problem? Thanks!
>>
>> On Mon, May 17, 2010 at 12:52 PM, Jun Shen <jun.shen.ut at gmail.com> wrote:
>>>
>>> 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, Shirley Bao <baoxinli at gmail.com> wrote:
>>> > 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 deleted]]
>>> >
>>> > ______________________________________________
>>> > 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.
>>> >
>>
>>
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list