Lattice plots in for loop - empty images created

后端 未结 1 1536
执笔经年
执笔经年 2020-12-11 22:18

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         


        
相关标签:
1条回答
  • 2020-12-11 22:41

    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()
    
    0 讨论(0)
提交回复
热议问题