From giampi at kth.se  Wed Feb 28 14:08:06 2007
From: giampi at kth.se (Giampiero Salvi)
Date: Wed, 28 Feb 2007 14:08:06 +0100 (CET)
Subject: [Rd] incremental plots with pdf and dev.copy
Message-ID: <Pine.LNX.4.58.0702281351150.21779@ctt14.speech.kth.se>

Hi,
I am trying to produce incremental plots directly using the pdf
device. I mean that I want to produce a plot, save it in a pdf
file, then add details and save the new plot in a new file, and
so on. Before I used to do this with x11, by just adding graphics to
a plot and then using dev.copy2eps at the right times for each eps
figure. Now I want to do this in batch mode and the x11 device is not
available.

This is how I go about it:

pdf(file="file1.pdf")          # create the first plot
dev.control(displaylist='enable') # allow copying print devices
plot(1:10)                     # first plot
dev.copy(pdf,file="file2.pdf") # create the second plot
dev.control(displaylist='enable')
dev.off(dev.prev())            # close the first plot
points(2,3)                    # add to the second plot
dev.copy(pdf,file="file3.pdf") # create the third plot
dev.off(dev.prev())            # close the second plot
points(3,2)                    # add to the third plot
dev.off()

The problem is this works only for the first two plots. For the
third I get an error at "dev.copy(pdf,file="file3.pdf")"

Error in dev.copy(pdf, file = "file3.pdf") :
        invalid graphics state

I also tried to remove the second dev.control statement, but in
that case the same error is delayed to the "points(3,2)" line
(plotting in the third plot).

Is this behaviour expected? Is there a better way to do what I'm
trying to do?

Thank you!
Giampiero

-- 
________________________________________________________
Giampiero Salvi, Ph.D.
www.speech.kth.se/~giampi          skype: giampierosalvi
Royal Institute of Technology, Speech, Music and Hearing
Lindstedtsv.    24,    SE-100 44,    Stockholm,   Sweden
Tel: +46-8-790 62 93                Fax: +46-8-790 78 54



[Rd] incremental plots with pdf and dev.copy
Giampiero Salvi