[R] Graphics 'snapshots' in Linux?

Marc Schwartz (via MN) mschwartz at mn.rr.com
Thu Sep 15 18:31:16 CEST 2005

On Thu, 2005-09-15 at 10:43 -0400, Tyler Smith wrote:
> Hi,
> I'm working on a MEPIS (Debian-based Linux) computer, using the 
> emacs/ESS package to do my R work. I've got some plots that I label 
> interactively using the locate function. With the Windows GUI there is 
> an option to take a snapshot of the graphics output, saving it as an 
> image file. Is there a way to do this with emacs/ESS?
> Thanks,
> Tyler


Take a look at ?dev.copy2eps and on the same page dev.copy(), which
enable you to copy the current X11 plot supported output devices.

You could do something like the following for an EPS file:

text(locator(1), "Place Text Here")
dev.copy2eps(file = "MyPlot.eps")

or the following for a PNG file:

par(bg = "white")
text(locator(1), "Place Text Here")
dev.copy(device = png, file = "MyPlot.png")

Note that in the first example, dev.off() is not required, as the EPS
output device is closed after the call.

Also, note in the second example, you will need to set the background to
white (unless already specified for whatever color you may be using), as
the default output file will have a transparent background, even though
the png() function shows the default as white. If my memory is correct
this is because the X11 device itself has a transparent background by
default and this is what is copied.


Marc Schwartz

More information about the R-help mailing list