richard.kittler@amd.com
2004-May-07 20:47 UTC
[R] Lattice xyplot - problem trying to produce multiple output files with a 'for' loop
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
Sundar Dorai-Raj
2004-May-07 20:56 UTC
[R] Lattice xyplot - problem trying to produce multiple output files with a 'for' loop
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.htmlSee the FAQ. you have to wrap the xyplot call with a print. I.e. for(...) { ... print(xyplot(...)) ... }