Re: [R] function in order to plot the same graph to postscript and pdf
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
[R] function in order to plot the same graph to postscript and pdf
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. __ 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
Re: [R] function in order to plot the same graph to postscript and pdf
On Wed, 9 Mar 2005 14:57:27 +0100 Ronny Klein wrote: 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. What are the myplot objects? Expressions or graphical objects that are printed? In any case, a good recommendation for this kind of stuff is to look at Sweave() in the utils package. I guess you're writing your thesis in LaTeX...and Sweave is a great possibility to mix LaTeX code and R code which for example generates both pdf and eps graphics. Z 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. __ 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 __ 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
Re: [R] function in order to plot the same graph to postscript and pdf
What are the myplot objects? Expressions or graphical objects that are printed? The myplot is something like this: plot(x) text(foo) etc. In any case, a good recommendation for this kind of stuff is to look at Sweave() in the utils package. I guess you're writing your thesis in LaTeX...and Sweave is a great possibility to mix LaTeX code and R code which for example generates both pdf and eps graphics. Thanks, I will have a look on it. 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
Re: [R] function in order to plot the same graph to postscript and pdf
On Wed, 9 Mar 2005 15:24:48 +0100 Ronny Klein wrote: What are the myplot objects? Expressions or graphical objects that are printed? The myplot is something like this: plot(x) text(foo) Aha, I was surprised that this worked for one of the two plots. You could pass myplot as an expression, e.g. myplot = expression(plot(x)), and then eval() that in the body of plot.both(). But personally, I wouldn't do that :-) and use Sweave instead. Z etc. In any case, a good recommendation for this kind of stuff is to look at Sweave() in the utils package. I guess you're writing your thesis in LaTeX...and Sweave is a great possibility to mix LaTeX code and R code which for example generates both pdf and eps graphics. Thanks, I will have a look on it. 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
Re: [R] function in order to plot the same graph to postscript and pdf
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) __ 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
Re: [R] function in order to plot the same graph to postscript and pdf
The myplot is something like this: plot(x) text(foo) Aha, I was surprised that this worked for one of the two plots. You could pass myplot as an expression, e.g. myplot = expression(plot(x)), and then eval() that in the body of plot.both(). I've followed your advice and changed my function to something like this: plot.both - function{myplot, filename}{ MYPLOT - expression(myplot) pdf(file=paste(filename, .pdf, sep=)) eval(myplot) dev.off() postscript(file=paste(filename, .eps, sep=)) eval(myplot) dev.off() } However the result is the same: the first one is actually printed but the second plot is empty. 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
RE: [R] function in order to plot the same graph to postscript and pdf
Use substitute() instead of expression(); choose to use either MYPLOT or myplot because they are different variables; and use parentheses around your function arguments instead of braces. -Original Message- From: Ronny Klein [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 09, 2005 12:22 PM To: Achim Zeileis Cc: r-help@stat.math.ethz.ch Subject: Re: [R] function in order to plot the same graph to postscript and pdf The myplot is something like this: plot(x) text(foo) Aha, I was surprised that this worked for one of the two plots. You could pass myplot as an expression, e.g. myplot = expression(plot(x)), and then eval() that in the body of plot.both(). I've followed your advice and changed my function to something like this: plot.both - function{myplot, filename}{ MYPLOT - expression(myplot) pdf(file=paste(filename, .pdf, sep=)) eval(myplot) dev.off() postscript(file=paste(filename, .eps, sep=)) eval(myplot) dev.off() } However the result is the same: the first one is actually printed but the second plot is empty. 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 __ 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
Re: [R] function in order to plot the same graph to postscript and pdf
On Wed, 9 Mar 2005 18:21:41 +0100 Ronny Klein wrote: The myplot is something like this: plot(x) text(foo) Aha, I was surprised that this worked for one of the two plots. You could pass myplot as an expression, e.g. myplot = expression(plot(x)), and then eval() that in the body of plot.both(). I've followed your advice Not quite... and changed my function to something like this: plot.both - function{myplot, filename}{ MYPLOT - expression(myplot) pdf(file=paste(filename, .pdf, sep=)) eval(myplot) dev.off() postscript(file=paste(filename, .eps, sep=)) eval(myplot) dev.off() } 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 However the result is the same: the first one is actually printed but the second plot is empty. 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