[R] how to plot and save plots in batch mode

1 view
Skip to first unread message

Kinoko

unread,
Nov 25, 2008, 5:11:44 AM11/25/08
to r-h...@r-project.org
Dear list,

This is not a question but a rather short note how to save a plot
if it was created in batch mode.
It took me like 2 hours to figure it out, I hope it can save time
for those who - like me - are not really fast in picking up
diosyncrasies of R. (as far as I remember I had no problems whatsoever
batch plotting in
gnuplot, matplotlib, matlab... )

The problem I had was that while I could plot and save my data using
RGui,
the same script did not work in batch mode.

plot(x,y, bla-bla... )
...
dev.set (2)
dev.print (device=png, file=outFile, bla-bla)

But this does not work in BATCH mode.
The error msg is:
"... can only print from a screen device"
Sure, the plotting window does not pop up in batch mode.

What I had to do was to to put a command:

windows()

before starting the plot. Now I can save my plots in batch mode

Well, I am more than sure, that there are more elegant solutions
without invoking the window...

______________________________________________
R-h...@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.

Greg Snow

unread,
Nov 25, 2008, 11:00:57 AM11/25/08
to Kinoko, r-h...@r-project.org
Why not just plot all your graphs directly to a file rather than sending them to a windows device that you are not looking at, then copying from there. The pdf and postscript devices will hold several plots in a single file, or the png device (and others) will automatically create 1 file per graph and you can either set the name for each, or use a set of sequential names. This should be easier, more straight forward, and more portable.

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg...@imail.org
801.408.8111

Reply all
Reply to author
Forward
0 new messages