[R] densityplot png in a for loop

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Feb 9 12:54:03 CET 2007


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



More information about the R-help mailing list