Dear R-users,

I have a question concerning the use of lattice plots within for-loops.
I want to create a png file containing a lattice histogram which works out
fine (part 1).
When I loop the whole code, the graphic file does not contain anything (part
2). 
I can fix it by wrapping the histogram function into a print command (part
3).
Why is that so? Why can I not loop it directly? 

TIA,
Mark

attach(iris)

### part 1
png(filename = "graphic_1.png")
  histogram( ~ Sepal.Length | Species, data = iris)
dev.off()

### part 2
for (i in c(1))
{
png(filename = "graphic_2.png")
  histogram( ~ Sepal.Length | Species, data = iris)
dev.off()
}

### part 3
for (i in c(1))
{
png(filename = "graphic_3.png")
  print(histogram( ~ Sepal.Length | Species, data = iris))
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.

Reply via email to