[R] Save multiple plots in a single pdf file when the plots are generated by a single plot command

Peter Ehlers ehlers at ucalgary.ca
Sat Jun 16 04:29:34 CEST 2012


On 2012-06-15 16:14, Debs Majumdar wrote:
> I thought that might be the case and did a couple of dev.off() even though I started a new R session. Each time I try to use the plot, it comes up with "pdf 2".
>
>

I think that the code for plot.lordif may have a bug; it contains this
line:

  if (Sys.info()["sysname"]=="Windows") dev.new(record=T) else par(ask=T)

which opens a new device on Windows. Just comment out that line and
save the function as myplot.lordif and (may not be necessary but
can't hurt) execute

   environment(myplot.lordif) <- environment(lordif)

and you should be okay using myplot.lordif() in place of plot.lordif().
Worked for me with the Anxiety age.dif example.

(I didn't read the code of plot.lordif carefully since, apparently,
the authors were unable to locate a keyboard with a spacebar or
tab-key.)

Peter Ehlers


>
> ----- Original Message -----
> From: R. Michael Weylandt<michael.weylandt at gmail.com>
> To: Debs Majumdar<debs_stata at yahoo.com>
> Cc: "r-help at r-project.org"<r-help at r-project.org>
> Sent: Friday, June 15, 2012 4:10 PM
> Subject: Re: [R] Save multiple plots in a single pdf file when the plots are generated by a single plot command
>
> It looks like you have one too many pdf objects open. The "pdf 2" that
> is printed indicates control was returned to another pdf device. Keep
> doing dev.off() until you get the message "null device 1" and then try
> it once again.
>
> Best,
> Michael
>
> On Fri, Jun 15, 2012 at 6:06 PM, Debs Majumdar<debs_stata at yahoo.com>  wrote:
>> I am using R 2.15.0 on Windows 7.
>>
>> It shows the plots on the screen. I can page-up and page-down to look at the different plots. It's when I want to save the plot, I get a blank pdf file (0 kb).
>>
>> #############
>>> pdf("education.pdf")
>>> plot(ed_dif, labels = c("White", "African American"))
>>> dev.off()
>> pdf
>>    2
>>>
>> ############
>>
>>
>>
>>
>> ----- Original Message -----
>> From: R. Michael Weylandt<michael.weylandt at gmail.com>
>> To: Debs Majumdar<debs_stata at yahoo.com>
>> Cc: "r-help at r-project.org"<r-help at r-project.org>
>> Sent: Friday, June 15, 2012 3:48 PM
>> Subject: Re: [R] Save multiple plots in a single pdf file when the plots are generated by a single plot command
>>
>> On Fri, Jun 15, 2012 at 4:39 PM, Debs Majumdar<debs_stata at yahoo.com>  wrote:
>>> Hi,
>>>
>>> I am trying to save multiple plots in a single pdf file when  the plots are generated by a single plot command. I am using the "lordif" package which generates multiple plots with one command.
>>>
>>> pdf("education.pdf")
>>> plot.lordif(ed_dif, labels = c("White", "African American"))
>>> dev.off()
>>>
>>> And this is not working at all. Thanks for your help.
>>
>> What do you mean by this? Is it the file not being created? Or its
>> blank? Or you get the wrong output? Does it work to print to a screen
>> device but not a pdf? Etc.
>>
>> Running the example in ?lordif, this works for me:
>>
>> pdf("test.pdf")
>> plot(age.DIF)
>> dev.off()
>>
>> What OS are you on and what version of R?
>>
>> In short, happy to help, but we need (much) more information.
>>
>> Michael
>>
>>>
>>> Debs
>>>
>>> ______________________________________________
>>> 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