0

How can I reset the graph to draw something new at the end of the loop?

For example,

I need to plot a graph. Then save the graph in a file, called "graph1.pdf"

Then loop this 3 times, saving files "graph2.pdf", "graph3.pdf"

If I put dev.off() at the end of the loop, R gave me the error message that

could not find function "device

I figured maybe it was because I shut down the PDF device.

So, maybe I should use dev.set() or dev.new() instead?

Thanks for any help!

Weijia
  • 79
  • 9
  • 3
    Can you post your code? Is your call to `pdf` inside the loop? – Jake Burkhead Jan 27 '14 at 17:32
  • Please post a [**minimal, reproducible example**](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). – Henrik Jan 27 '14 at 17:46
  • I've never seen "could not find function device" after `dev.off()`; anyway, you could try `plot.new()` or `frame()` maybe? – rawr Jan 27 '14 at 17:55
  • @rawr, I figure out that I need to add "device=pdf" in the ggsave(), thanks anyway – Weijia Jan 27 '14 at 19:11

0 Answers0