Skip to content

Multi-page PDF using dev.copy2pdf(filename, onefile=TRUE)?

4 messages · Doug Hill, ilai, David Winsemius

#
Doug,
dev.copy2pdf closes the connection after it's "done", so onefile is
meaningless. To look at each plot before copy to a single pdf, you
could open a pdf(...) but revert between it and your graphic device:
graphics.off()
plot(1:7, 1:7)
x11c<- dev.cur()       # your current graphics device
pdf(file="test.pdf")
dev.set(which=x11c)   # back from pdf
dev.copy()                  # copy
dev.set(which=x11c)    # back to graphic
plot(1:5, 1:5,col=2,pch=2)
dev.copy()
dev.set(which=x11c)
# ...   etc. however many more plots
# don't forget to close the pdf device at the end:
dev.off(which=x11c+1)
# Both plots are in 'test.pdf'

Depending on your application you might be able to simplify things
with dev.next/dev.prev, or wrap this sequence into a little helper
function to be used in a loop.

Enjoy,
Elai
On Mon, Feb 6, 2012 at 6:44 AM, Doug Hill <logickle at yahoo.com> wrote:
#
On Feb 6, 2012, at 2:51 PM, Doug Hill wrote:

            
You are confused about the difference of a named variable and its  
contents. There is no X11 device in that solution,  just a name for  
the current device which in your case is probably not an X11 device.  
If you looked at the value of `x11c`, you would see it's just a number.

Elai is just switching back and forth between the screen device and  
the file device.