Skip to content

Can I save R graphs as a R objects

6 messages · vikrant, Paul Hiemstra, Henrique Dallazuanna +3 more

#
vikrant wrote:
When you use the graphics functions from the lattice package (e.g. 
xyplot) you can save them to a file (see ?save) because it creates an 
object that represents the graph. When using the standard plot system I 
think this is not possible. But if you have the original data and an R 
script to make the graph, you don't need to save the graph explicitly. 
When processing the data for the graph takes a long time, you can run 
the script to just before making the graph and save all the appropriate 
objects to disk. Next time you only need to load your data (see ?load) 
and make the plot.

cheers,
Paul
#
You can use the recordPlot function from base package also
On Fri, Jan 15, 2010 at 7:26 AM, vikrant <vikrant.shimpi at tcs.com> wrote:

  
    
#
On 1/15/10, vikrant <vikrant.shimpi at tcs.com> wrote:
Sort of, using playwith. You can always try to place the the plot call
inside playwith(). For example,
require(playwith)
playwith(plot(1:10))

Liviu
#
As a general rule, you really do not want to edit graphs by pointing/clicking/dragging.  It may seem an easy way to make some modifications, but in the long run it will become more of a headache than a help.  Better to create a script with the commands to create the plot, then if there is some change you want made, find the correct change or addition to the script and rerun the script.  That way when later on you have a similar project and want to create the same or similar graph, you can just run the script again with the new data, making any minor changes that you need.

On the other hand if you create the basic plot then edit it using point/click/drag style tools, then a couple months later when you find that there was a typo in the data and you need to recreate the graph (not as rare an event as we would like), you will first need to remember how you created the graph, then you will need to remember all the point/click/drag steps that you took (and redo them).  It is just simpler to use the script.

Having said that, if you still feel the need to modify a plot using a mouse (don't complain when you have to redo all the steps to redo the graph) then some options include:

Save the graph as an svg file (Cairo device, or other package) then use inkscape or other program to edit it.
Save the graph as a fig file and use xfig/winfig/jfig to edit it.
Save/copy the graph as a windows meta file and use Excel/Word to edit it.

But the R paradigm is really to use a script to create the correct graph in the first place rather than give an incorrect graph and expect the user to use non-reproducible post-hoc modifications.

Hope this helps,