[R] Lattice xyplot - problem trying to produce multiple output files with a 'for' loop

Sundar Dorai-Raj sundar.dorai-raj at PDF.COM
Fri May 7 22:56:37 CEST 2004



richard.kittler at amd.com wrote:

> I am stuck on trying to get the Lattice xyplot to output a separate PNG file each time through my 'for' loop.  The files get produced but are empty.
> 
> Here is the code.  I'm running 1.9 on Windows.  BTW is there a more efficient way of creating the separate output files than looping over the levels and subsetting? 
> 
> .........................................................
> lev <- levels(ds$TR)
> 
> for (byvar in lev) {
> 
>  file.png <- paste("u:/data/R/Scatter_CTY_HWY_CO_TR", byvar,  ".png", sep="")
> 
>  trellis.device( device="png", file=file.png, 
>      width=1000, height=1000, pointsize=20, bg="transparent" )
> 
>  ds1 <- subset(ds, TR == byvar, select=c(CTY, HWY, CO))
> 
>  xyplot( ds1$CTY ~ ds1$HWY, groups=ds1$CO,
>     auto.key=list(space="right"), ylab="CTY", xlab="HWY")
> 
>  dev.off()
> 
> }
> .........................................................
> 
> --Rich
> 
> Richard Kittler 
> AMD TDG
> 408-749-4099
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

See the FAQ.

you have to wrap the xyplot call with a print. I.e.

for(...) {
   ...
   print(xyplot(...))
   ...
}




More information about the R-help mailing list