I want to plot and then save graphs in a loop. The problem is that the graphs take too long to plot. Execution jumps to the save command (dev.copy2eps) before the plotting has finished, and so the wrong graph is saved. I works fine if I step through slowly command at a time, but I want to do it programmatically. How can I tell R to wait for the graph to finish? I have tried Sys.sleep, but that doesn't work. -- aleblanc
There are several ways.
What I often use is:
pdf(...) # Check: ?pdf
for(i in something)
{
plot(things)
}
dev.off()
And it works fine.
----------------Contact
Details:-------------------------------------------------------
Contact me: Tal.Galili@gmail.com | 972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
----------------------------------------------------------------------------------------------
On Fri, Oct 22, 2010 at 11:54 AM, <news@aleblanc.cotse.net> wrote:
> I want to plot and then save graphs in a loop.
> The problem is that the graphs take too long to plot. Execution jumps to
> the save command (dev.copy2eps)
> before the plotting has finished, and so the wrong graph is saved.
>
> I works fine if I step through slowly command at a time, but I want to do
> it programmatically.
> How can I tell R to wait for the graph to finish?
> I have tried Sys.sleep, but that doesn't work.
>
>
> --
> aleblanc
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
I suspect that using "dev.copy2eps" Is not going to help you here.
Please try again using:
pdf(...) # Check: ?pdf
for(i in something)
{
plot(things)
}
dev.off()
But give pdf() the file path.
Make sure you can make it work with simple plots. then check it on your
situation, and let us know if it works :)
(I had it work with very heavy plots - so I trust it will work for you)
(p.s: please keep cc'ing the r-help list so others will know the stage of
your problem, in case others would like to add more help :) )
Cheers,
Tal
----------------Contact
Details:-------------------------------------------------------
Contact me: Tal.Galili@gmail.com | 972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
----------------------------------------------------------------------------------------------
On Fri, Oct 22, 2010 at 8:17 PM, <news@aleblanc.cotse.net> wrote:
> dev.copy2eps
[[alternative HTML version deleted]]