How to page multiple plots in R in separate jpeg files?

a 夏天 提交于 2019-12-05 11:43:23

I think this should work

somevar <- 1
while(somevar <= n) {
  jpg(sprintf("%s%03.jpg", filename, somevar))
  plot(data[somevar])
  dev.off()
  somevar <- somevar + 1
}

Plotting goes from device opening (here jpeg(...)) to dev.off(). You control the filename (where I corrected your use of paste() to sprintf()) and the loop.

What happens if you remove the dev.new() from your code? The jpg function/device should generate the multiple files following your pattern as long as you keep writing to the jpg device (the device.new call starts a new device each time, hence the pdf files).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!