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

richard.kittler@amd.com richard.kittler at amd.com
Fri May 7 22:47:40 CEST 2004


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




More information about the R-help mailing list