Skip to content

Extract data from a PNG/TIFF

December 5, 2018

Sometimes it’s useful to be able to extract data from a published figure. If the figure isn’t a vector based format (for which the numeric data is probably still in the file), it’s possible to digitize the image with R, click the points and extract it that way. The digitize package is simple to use for this purpose…

If you save the top figure from here to a PNG called “Fig2a_Kreners2015” in your working directory, you can digitize the three lines and replicate the figure (or do other stuff if you so wish) as follows

library(digitize)
dig10 <- digitize("Fig2a_Kremers2015.png") # do the solid line
dig15 <- digitize("Fig2a_Kremers2015.png") # do the dashed line
dig20 <- digitize("Fig2a_Kremers2015.png") # do the dotted line

# rename the first variable
names(dig10)[1] <- names(dig15)[1] <- names(dig20)[1] <- "age"

plot(dig10, type = "l")
lines(dig15, lty = 2)
lines(dig20, lty = 3)

Fig2a_Kremers2015_rep

Easy huh? It just gets a bit laborious with many points… 🙂

 

Advertisements

From → R

2 Comments
  1. Gautier de Montmollin permalink

    Very interesting, thanks! If the clicking becomes too tedious (multiple or complex curves), you can alternatively use an automatic tool of mine, called Recurve – open-source, @ https://gen-img-dec.sourceforge.io/, https://github.com/svn2github/gid . It scans a picture and produces a .csv from it.

    • Thanks for that… such a tool would certainly be useful for plot with lots of points…

Leave a Reply

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: