[R] Lattice in a loop does not produce output
I cannot understand why xyplot does not work within a simple for loop. This works up to the for loop; inside the for loop the png files are opened and closed, but nothing is plotted. No error messages are written to the console either. This is the case on both Windows and Linux. By the way, running the script below on Linux using source() does not even produce the first xyplot. This is less of an issue for me though. #! usr/bin/env R # Test lattice loop rm(list=ls()) x-1:16 y-2*x-1 z-rep(c('A','B','C','D'),4) xyz-data.frame(x=x,y=y,z=z) require(lattice) png('Test.png') xyplot(y~x|z) dev.off() for (i in 1:5) { f-paste('Test',i,'.png',sep='') png(f) xyplot(y~x|z) dev.off() } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Lattice in a loop does not produce output
Check the FAQs. You need an explicit 'print' on the lattice call: for (i in 1:5) { f-paste('Test',i,'.png',sep='') png(f) print(xyplot(y~x|z)) dev.off() } On Tue, Aug 18, 2009 at 8:13 AM, Alex van der Spekam...@xs4all.nl wrote: I cannot understand why xyplot does not work within a simple for loop. This works up to the for loop; inside the for loop the png files are opened and closed, but nothing is plotted. No error messages are written to the console either. This is the case on both Windows and Linux. By the way, running the script below on Linux using source() does not even produce the first xyplot. This is less of an issue for me though. #! usr/bin/env R # Test lattice loop rm(list=ls()) x-1:16 y-2*x-1 z-rep(c('A','B','C','D'),4) xyz-data.frame(x=x,y=y,z=z) require(lattice) png('Test.png') xyplot(y~x|z) dev.off() for (i in 1:5) { f-paste('Test',i,'.png',sep='') png(f) xyplot(y~x|z) dev.off() } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Lattice in a loop does not produce output
Lattice objects must be assigned and deliberately printed: png(test.png) p - xyplot(y~x|z) plot(p) dev.off() Should fix both problems. Bryan * Bryan Hanson Professor of Chemistry Biochemistry DePauw University, Greencastle IN USA On 8/18/09 8:13 AM, Alex van der Spek am...@xs4all.nl wrote: I cannot understand why xyplot does not work within a simple for loop. This works up to the for loop; inside the for loop the png files are opened and closed, but nothing is plotted. No error messages are written to the console either. This is the case on both Windows and Linux. By the way, running the script below on Linux using source() does not even produce the first xyplot. This is less of an issue for me though. #! usr/bin/env R # Test lattice loop rm(list=ls()) x-1:16 y-2*x-1 z-rep(c('A','B','C','D'),4) xyz-data.frame(x=x,y=y,z=z) require(lattice) png('Test.png') xyplot(y~x|z) dev.off() for (i in 1:5) { f-paste('Test',i,'.png',sep='') png(f) xyplot(y~x|z) dev.off() } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Lattice in a loop does not produce output
Try printing the plot created. print(xyplot(...)) -- Dr. Mark Wardle Specialist registrar, Neurology (Sent from my mobile) On 18 Aug 2009, at 13:13, Alex van der Spek am...@xs4all.nl wrote: I cannot understand why xyplot does not work within a simple for loop. This works up to the for loop; inside the for loop the png files are opened and closed, but nothing is plotted. No error messages are written to the console either. This is the case on both Windows and Linux. By the way, running the script below on Linux using source() does not even produce the first xyplot. This is less of an issue for me though. #! usr/bin/env R # Test lattice loop rm(list=ls()) x-1:16 y-2*x-1 z-rep(c('A','B','C','D'),4) xyz-data.frame(x=x,y=y,z=z) require(lattice) png('Test.png') xyplot(y~x|z) dev.off() for (i in 1:5) { f-paste('Test',i,'.png',sep='') png(f) xyplot(y~x|z) dev.off() } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.