seascape models

How to digitise graphs using R

I recent had reason to digitise some graphs from published papers. You could buy a program to help you do this, but it is actually also possible with R. Here is how to do it.

First, take your graph, for instance, here I have taken a screen shot of a map from a paper on ecosystem modelling in Australia. I want to know the coordinates of each of the models plotted on the map. Just the centre point will do for now. You could extract the edges of all the polygons using this method too, but it would be tedious.

Then get and load in the PNG and raster packages, which will allow us to load the image file and plot it in R:

library(png)
library(raster)
pic <- as.raster(readPNG('sole.png'))

Now plot the image on a graph that scales (0,1), so we know where everything has been plotted.

Now we have our true coordinates stored in xvals and yvals. We can replot to check them or save them as a csv for later use. Here we will use the maps library, so we can quickly plot our points back to a map of Australia: