Improving R Figures with Inkscape

Here's an example of a figure made of three separate graphs, combined and cleaned up in Inkscape.

If you’re going to publish a graph or a model, you want something that looks clean and professional.  But R output, like graphs or a various plots, often don’t come out the way you want.  Even if you’re a wiz at manipulating the plot command, you can probably still see room for improvement.  How many times have you spent 30 minutes or more trying to figure out what parameter moves you label over 3 pixels, all the while dreaming that you could just reach into the computer and move the little bugger yourself?  I have the solution!  Here’s how you do it:

  1. Write your script in R to generate whatever plot or image you need.  Make sure all the labels are in there that you need R to generate.  Today I’m making ordination plots with the vegan package.

    Here's an example of a typical output from R. It's generally ok, but wouldn't you want to move some stuff around?

  2. Save the plot as a PDF file.  To save it, activate the plot window -> File -> Save As -> PDF  (I mean it.  Not an image file, but a PDF.  And I know it looks ugly, but we’ll fix it later.)  NOTE: Make sure you don’t  resize the image window before you save the file.  In the past I’ve had some funny things happen (like letters rotating 180°) if I tried to resize it before I saved it.  We’ll do any resizing later.
  3. Open up your favorite vector illustration software.  I like Inkscape because it works and it’s free/open source.  I highly recommend it.
  4. In Inkscape, File -> Open -> Find your PDF -> click OK -> pick the settings you like in the dialog that pops up -> click OK.
  5. Save it as an SVG file.  You’ll be saving now in Inkscape’s native format and have the original PDF in case you need to go back to the start.
  6. Now is the fun part… you get to make the image look better.  There are some tricks…
    1. If you can’t select something, like a text box, it’s probably a part of a group.  The bottom of the screen will tell you if you’ve selected a group.  To fix this, just click the Ungroup button.  For example, everything that falls inside the plot area gets grouped – so all the points, lines, and even a white box that you probably don’t even notice are in a group.
    2. Layers are your friend.  Put each type of item in it’s own layer.  For example, I like to put my axes in one layer, my graphed points in another, all the labels in another, etc.
    3. Ctrl + Alt + V (paste in place) is your other friend.  Use it to remove items from one layer into another without messing up the alignment.
    4. Did the import turn all of your points into something strange like q’ s?  Mine did.  Use the “Replace Text” tool in the Extension menu under Text.  If you change all you “q” points into “o”, you can then convert the o’s to paths and fill them with black so they look like points.
  7. Finally, export your image or save it as a new PDF.
Advertisements

About micheletobias

I lead two lives - one as an artist and the other as a scientist. More and more I'm finding my two worlds colliding, and it's not the disaster you might expect. View all posts by micheletobias

5 responses to “Improving R Figures with Inkscape

I'd love to hear what you think. Leave a comment!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: