[R] savePlot and dev.copy
p.murrell at auckland.ac.nz
Tue Oct 31 21:08:15 CET 2006
Mike Prager wrote:
> Dear R gurus,
> R 2.4.0 under Windows XP.
> We have developed several dozen R functions to make and save
> specialized plots. These use savePlot() to optionally save the
> plot to files (eps, jpg, png, ...).
> The thought has come up of putting the functions into an R
> package. Because savePlot is available only on Windows, we
> would instead detect the OS and use dev.copy in place of
> savePlot when not running under Windows.
> My question is, if this code is rewritten anyway, what are the
> pros and cons of using dev.copy under *all* operating systems
> vs. using savePlot on Windows and dev.copy on other platforms?
The underlying mechanisms of dev.copy() and savePlot() are identical --
copy the display list from one device to another -- but savePlot() has
some niceties wrapped around the outside.
These boil down to making the copy the same size as the original. If
you use dev.copy() naively, you can get a copy which is a very different
size from the original. The function dev.print() does a bit better in
terms of retaining the original size, but there is trouble when you copy
from a device for which the size is specified in inches [like windows(),
x11(), postscript() and pdf()] to a device for which the size is in
pixels [png(), jpeg(), bitmap()].
savePlot() handles all of the sizing problems for you (but only works on
Windows). dev.copy() works everywhere, but you would have to do a bit
of mucking about yourself to get around the sizing problems -- see the
source for dev.print() for a starting point.
The authors of the Windows device might have more to say.
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
64 9 3737599 x85392
paul at stat.auckland.ac.nz
More information about the R-help