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

From: Ronny Klein <ronny.klein_at_wiwi.uni-halle.de>
Date: Thu 10 Mar 2005 - 19:32:55 EST

> I guess you would want eval(MYPLOT) there?
>
> But the function above works if you say
> plot.both(myplot = expression(plot(x)), filename = "foo")
> and that is what I said above: set myplot = expression(plot(x)).
> Z

My syntax in the example was a little bit messed, sorry for that.

However Gabor Grothendieck's reply has brought me to the solution. The following function does the job right:

print.both <- function(myplot, filename){

     pdf(file=paste(filename, ".pdf", sep=""))
     postscript(file=paste(filename, ".eps", sep=""))
    dev.control(displaylist="enable")
    myplot
    dev.copy(which=dev.next())
    graphics.off()
}

The dev.control(displaylist="enable") is necessary here because only then R does record the plot and dev.copy can be used.

So, thank you all for your help.

Ronny



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Mar 10 19:53:16 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:42 EST