[R] function in order to plot the same graph to postscript and pdf

Gabor Grothendieck ggrothendieck at myway.com
Wed Mar 9 15:55:09 CET 2005


Ronny Klein <ronny.klein <at> wiwi.uni-halle.de> writes:

: 
: Hi,
: 
: I've written a function in order to plot the same graph in a postcript and 
in 
: a pdf file. Unfortunately, the second graph is always empty, i.e.:
: 
: plot.both <- function{myplot, filename}{
:   pdf(file=paste(filename, ".pdf", sep=""))
:    myplot
:   dev.off()
:   postscript(file=paste(filename, ".eps", sep=""))
:    myplot
:   dev.off()
: }
: 
: yields in a correct pdf but an empty eps file. However something like this:
: 
: plot.both <- function{myplot1, myplot2, filename}{
:   pdf(file=paste(filename, ".pdf", sep=""))
:    myplot1
:   dev.off()
:   postscript(file=paste(filename, ".eps", sep=""))
:    myplot2
:   dev.off()
: }
: 
: yields the expected results even if myplot1 and myplot2 are identical.
: 
: Does somebody know, how I can implement the desired (first) function?
: 
: Ronny
: 
: PS: My system is: Linux Debian Unstable and R-Version:  2.0.1.
: 

The following works on Windows R 2.1.0.  Don't know about Linux:

dev.control(displaylist="enable") # enable display list
plot(1:10)
myplot <- recordPlot() # load displaylist into variable
savePlot("myplot", type = "pdf")
savePlot("myplot", type = "ps")




More information about the R-help mailing list