[R] function in order to plot the same graph to postscript an d pdf
Liaw, Andy
andy_liaw at merck.com
Wed Mar 9 18:39:53 CET 2005
This works for me:
plot.both <- function(expr, filename) {
pdf(file=paste(filename, ".pdf", sep=""))
eval(expr)
dev.off()
postscript(file=paste(filename, ".eps", sep=""))
eval(expr)
dev.off()
}
plot.both(expression(plot(1:10)), "testboth")
Andy
PS: Please make sure you post correct code. The code you posted has syntax
(and other) errors.
> From: Ronny Klein
>
> > > 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 at 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
>
>
>
More information about the R-help
mailing list