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
The first part is an FAQ (in R docs, and on SO): you must print(mylatticeplot)
, when not interactive.
In addition, your approach does not work in RStudio, for example.
Error in savePlot(paste0("file_", f), "png") :
can only copy from 'windows' devices
The recommended way works better, and is less work:
png("file_%03d.png")
for (f in unique(df$month)) {
p = bwplot(x ~ country|type, data = df[df$month == f,], panel=function(...) {
panel.abline(h=0, col="green")
panel.bwplot(...)
})
print(p)
}
dev.off()