Hi all, I am trying to plot a list of densityplots as png files, but when I do it in a for loop, I get empty png files as a result. If I manually run the instructions inside the loop, it works... any hints? library(lattice) names_list = c("alfa","beta","gamma") for (i in 1:length(names_list)) { pngfile = paste("example_",names_list[i],".png", sep="") png(file=pngfile, width=1280,height=1024) input = rnorm(1000,i) densityplot(~input, plot.points=FALSE, auto.key=TRUE ) dev.off() } Thanks, Albert.
Hi Most probably see the FAQ 7.22 Why do lattice/trellis graphics not work? HTH Petr On 9 Feb 2007 at 11:28, Albert Vilella wrote: Date sent: Fri, 9 Feb 2007 11:28:07 +0000 From: "Albert Vilella" <avilella at gmail.com> To: r-help at stat.math.ethz.ch Subject: [R] densityplot png in a for loop> Hi all, > > I am trying to plot a list of densityplots as png files, but when I do > it in a for loop, I get empty png files as a result. > > If I manually run the instructions inside the loop, it works... any > hints? > > library(lattice) > names_list = c("alfa","beta","gamma") > for (i in 1:length(names_list)) { > pngfile = paste("example_",names_list[i],".png", sep="") > png(file=pngfile, width=1280,height=1024) > input = rnorm(1000,i) > densityplot(~input, > plot.points=FALSE, > auto.key=TRUE > ) > dev.off() > } > > Thanks, > > Albert. > > ______________________________________________ > 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 and provide commented, > minimal, self-contained, reproducible code.Petr Pikal petr.pikal at precheza.cz
This is FAQ Q7.22 On Fri, 9 Feb 2007, Albert Vilella wrote:> Hi all, > > I am trying to plot a list of densityplots as png files, but when I do > it in a for loop, I get empty png files as a result. > > If I manually run the instructions inside the loop, it works... any hints? > > library(lattice) > names_list = c("alfa","beta","gamma") > for (i in 1:length(names_list)) { > pngfile = paste("example_",names_list[i],".png", sep="") > png(file=pngfile, width=1280,height=1024) > input = rnorm(1000,i) > densityplot(~input, > plot.points=FALSE, > auto.key=TRUE > ) > dev.off() > } > > Thanks, > > Albert. > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Check out: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f On 2/9/07, Albert Vilella <avilella at gmail.com> wrote:> Hi all, > > I am trying to plot a list of densityplots as png files, but when I do > it in a for loop, I get empty png files as a result. > > If I manually run the instructions inside the loop, it works... any hints? > > library(lattice) > names_list = c("alfa","beta","gamma") > for (i in 1:length(names_list)) { > pngfile = paste("example_",names_list[i],".png", sep="") > png(file=pngfile, width=1280,height=1024) > input = rnorm(1000,i) > densityplot(~input, > plot.points=FALSE, > auto.key=TRUE > ) > dev.off() > } > > Thanks, > > Albert. > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. >