[R] Saving trellis output to files in scripts...

Liaw, Andy andy_liaw at merck.com
Tue Aug 9 18:34:12 CEST 2005


This is in the FAQ:  You need to wrap any trellis calls in functions or
scripts in print().

Andy

> From: Jamieson Cobleigh
> 
> With much help from Chuck Cleland, I was able to get xyplot to
> generate the plot I wanted.  I'm trying to write a script (that can be
> read using source("file")) to create the plots I want and save them to
> files.
> 
> If I type the following lines into the R (in interactive mode), the
> correct plot gets saved into the file myfile.ps with a size of 4,096
> bytes:
> 
> ----------------------------
> require(lattice)
> 
> trellis.device("postscript", file="myfile.ps", color=FALSE,
> paper="letter", horizontal=TRUE, onefile=TRUE)
> 
> xyplot(y ~ x, type="b", data.frame(x=1:5, y=5:1))
> 
> dev.off()
> ----------------------------
> 
> However, if I put the same lines into a file, "temp.txt", and type
> source("temp.txt") into R, then myfile.ps ends up with a size of 2,332
> bytes and shows a blank page when loaded into ghostscript.
> 
> When run using source, it looks like the device is not getting closed
> correctly since if I type source("temp.txt") and then dev.list() R
> responds:  "postscript 2"
> 
> If I type dev.off(), the file size then increases to 4,277 bytes, but
> then the ps file is malformed.
> 
> Anyone know how to make this work?
> 
> Jamie
> 
> ______________________________________________
> 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