[R] Exporting R graphs (review)

ucgamdo@ucl.ac.uk ucgamdo at ucl.ac.uk
Wed Aug 27 16:21:36 CEST 2003


Hi guys,

   Yesterday I posted my first couple of questions (see bottom of this
message) to this forum and I would like to thank you guys for all the
useful feedback I got. I just would like to make some comments:

1. Exporting R graphs as vector graphics:

The best answer came from Thomas Lumley <tlumley at u.washington.edu>
He suggested using the RSvgDevice package. As far as I know SVG graphics
can be manipulated with OpenOffice and also with sodipodi, I'll check this
package out asap. This should apply to linux and win users.

Too all bitmap (i.e. jpeg, png, etc.) enthusiasts, thanks a lot for your
help. I knew already that R can create high quality bitmap files that can
then be greatly enhanced with the Gimp. However, a bitmap is a bitmap: they
are usually larger than vector or postscript files and they do not allow
fine control of vector objects. For windows users, I strongly encourage
them to try copying their graphs to the clipboard as metafiles, and then
pasting the result into OpenOffice Draw, you will have to unmask, and
ungroup the object before being able to manipulate it. You will see how
easy is just to select one point from a scatter plot, resize it, move it,
etc. without any loss of resolution.

2. Recording graphs:

The best answer came from MSchwartz at MedAnalytics.com it was just what I was
looking for, so everybody, please try what he suggested:

What you could do is to use recordPlot() to save the version of the plot
to a file, prior to the point at which you start annotating, so that you
can return to that same point if you make a mistake.

As a brief example, with output to the display:

# Do a quick scatterplot
plot(1:10)

# Now save the plot's current state
myplot <- recordPlot()

# Now save display list 'myplot' to a file
save(myplot, file = "myplot")

# Now place some text on the plot
# Click on the plot with the mouse after 
# this line executes, to indicate where you
# want the text located.
text(locator(1), "Some Text", adj=0)

# OK, didn't like where I located the text
# so load and redisplay the base plot
load("myplot")
myplot

# Now re-locate the text
text(locator(1), "Some Text", adj=0)


############################################################################
###
Old post:

Hi,

	I have been a happy user of R for windows for more than a year, however,
recently, I started using linux as my operating system and now I have
practically switched completely. Of course, I still use R with linux,
however, certain nice features of R in windows seem to be missing or
hidden. I need help in basically two points:

1. In windows, I could copy the contents of a window graphic's device as a
windows metafile, and then I could paste the metafile into OpenOffice draw.
The advantage of doing this is that I could then manipulate my graph as a
vector object and get absolute control of every line, point, etc. I could
also paste several graphs in the same page and resize them arbitrarily,
which is a lot nicer than using the screen.split() or frame() functions in
R. Is there any equivalent method I could use to get R graphics into
OpenOffice draw in linux?, keeping the same functionality of course.

2. In windows, I could 'record' a graph, and then undo any changes made.
For example, if I misplaced a text label somewhere, I could go back and
place it again properly without having to re-plot everything again. I have
been browsing the R documentation and found some recording functions for
graphic devices but they do not seem to be exactly what I am looking for.
Is there any way I can access the display list of a device and change it?
Some of my plots are the product of tedious and long simulations which I
wouldn't like to repeat if I make a mistake labelling my plots, placing
legends, etc.

Thanks a lot for any help you can offer me,
M.




More information about the R-help mailing list