Didrik Vanhoenacker, 2009.

Save and edit graphs

You can create graphs from R in a variety of image formats. This manual is about how you can work with your graphs after you have created them in R.

Pimp the graph in R or afterwards?

It might be tempting to create a simple graph in R, and then edit it in image software, like Inkscape, or in Powerpoint. However, it is often a good idea to pimp the graph with code in R, and then save the code. This way you can correct mistakes in your data set and recreate your graphs with one copy-paste, instead of two billion Inkscape clicks. For code pimping in R, see the Pimp Your Graph manual.

Save graphs

  • Right-click on the graph and choose copy as bitmap or metafile.
  • With the graph window active, ctrl + c (copies the graph as bitmap)
  • With the graph window active, File  Save as...

Suggestions:

Fast: just copy-paste to word.

For low resolution images on a windows PC, save directly as png.

For high resolution images, save as pdf.

Image formats

Type / Size / Suitable for: / Comment
bitmap =
.bmp / fixed size / powerpoint, word / default ctrl+ c
png / fixed size / powerpoint, web / similar to gif
jpg / fixed size / photos rather than graphs
metafile =
.emf / scalable size / powerpoint, word / only R for windows, edit in powerpoint
pdf / scalable size / printing / possible to edit in Inkscape

Edit pdf:s in Inkscape

  • Start Inkscape
  • File  Open (swe = Arkiv  Öppna)
  • Open your file. In the next window, just Ok the settings.

Points (•) q when you import a pdf to Inkscape

The dot symbols pch=19 and pch=20 sometimes becomes q when you import a pdf toan image program. Either you use another symbol or you can change the colour opacity (swe = genomskinlighet) slightly:

plot(rnorm(10),rnorm(10),pch=20,col=rgb(0,0,0,.99))

Edit in Inkscape

  • You may have to ungroup (swe =Avgruppera) objects (like dots) to edit them. Mark an object, right-click, and choose ungroup (swe =Avgruppera). You may have to do this two times.
  • Mark the object you want to edit. Hold down shift to mark several objects at the same time.

Useful editing functions are for example:

  • Object  Transform (Ctrl + Shift + M). Then Scale.
  • Text  Text (Ctrl + Shift + T)

Play around. I am no Inkscape guru.

Save from Inkscape

When your done (or if you didn’t have to do any editing), save either as pdf or png.

png

  • File  Export as Bitmap (swe = Arkiv  Exportera bitmapsbild)
  • Choose an appropriate size. To print a 10 x 10 cm in good quality will require ca. 2000 x 2000 dots (swe=bildpunkter).
  • Choose your folder (probably My Documents).
  • Export

pdf

  • File (swe = Arkiv)  Save as.
  • Choose your folder (probably My Documents).
  • Change Inkscape SVG to PDF via Cairo
  • Save

If you’re not done you can save as Inkscape format .svg and continue later.

  • File (swe = Arkiv)  Save as.
  • Choose your folder (probably My Documents ).
  • Save (as Inkscape SVG)

Edit metafiles in Powerpoint (windows only)

Not really recommended, but sometimes fast and dirty is the way to go…

  • Right-click on your graph in R Save as metafile
  • Paste into powerpoint.
  • Right-click on the graph. Group  Ungroup. Do you want to convert? YES!
  • Right-click on the graph again. Group  Ungroup.
  • You may want to delete the large white rectangle. Then it's easier to mark other things.
  • Pimp!