Extract data from a PNG/TIFF

December 5, 2018
By

(This article was first published on R – Insights of a PhD, and kindly contributed to R-bloggers)

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… 🙂

 

To leave a comment for the author, please follow the link and comment on their blog: R – Insights of a PhD.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)