I want to produce several lattice plots in a for loop, but it does create empty images!!!
for (f in unique(df$month)) {
plot.new()
bwplot(x ~ country|type, data = df[df$month == f,], panel=function(...) {
panel.abline(h=0, col="green")
panel.bwplot(...)
})
savePlot(paste0("file_", f), "png")
}
When I run the inner of the for loop "by hand", it works, but in loop it stops working. Why?
Here is the code to generate the data:
set.seed(123)
n <- 300
country <- sample(c("Europe", "Africa", "Asia", "Australia"), n, replace = TRUE)
type <- sample(c("city", "river", "village"), n, replace = TRUE)
month <- sample(c("may", "june", "july"), n, replace = TRUE)
x <- rnorm(n)
df <- data.frame(x, country, type, month)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…