<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/extract-data-from-a-png-tiff/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://aghaynes.wordpress.com/2018/12/05/extract-data-from-a-png-tiff/"> R – Insights of a PhD</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>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…</p>
<p>If you save the top figure from <a rel="nofollow" href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4551172/figure/fig2/" target="_blank">here</a> 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</p>
<pre>library(digitize)
dig10 &lt;- digitize(&quot;Fig2a_Kremers2015.png&quot;) # do the solid line
dig15 &lt;- digitize(&quot;Fig2a_Kremers2015.png&quot;) # do the dashed line
dig20 &lt;- digitize(&quot;Fig2a_Kremers2015.png&quot;) # do the dotted line

# rename the first variable
names(dig10)[1] &lt;- names(dig15)[1] &lt;- names(dig20)[1] &lt;- &quot;age&quot;

plot(dig10, type = &quot;l&quot;)
lines(dig15, lty = 2)
lines(dig20, lty = 3)</pre>
<p><img data-orig-file="https://aghaynes.files.wordpress.com/2018/12/fig2a_kremers2015_rep.png?w=456" data-orig-size="624,345" data-medium-file="https://aghaynes.files.wordpress.com/2018/12/fig2a_kremers2015_rep.png?w=456?w=300" data-attachment-id="401" data-image-meta="{" data-image-description="" src="https://aghaynes.files.wordpress.com/2018/12/fig2a_kremers2015_rep.png?w=456" data-permalink="https://aghaynes.wordpress.com/2018/12/05/extract-data-from-a-png-tiff/fig2a_kremers2015_rep/" data-large-file="https://aghaynes.files.wordpress.com/2018/12/fig2a_kremers2015_rep.png?w=456?w=497" alt="Fig2a_Kremers2015_rep" data-image-title="Fig2a_Kremers2015_rep" sizes="(max-width: 497px) 100vw, 497px" data-comments-opened="1" class="wp-image-401" data-recalc-dims="1"></p>
<p>Easy huh? It just gets a bit laborious with many points… <img alt="🙂" src="https://i0.wp.com/s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f642.png?w=456&ssl=1" class="wp-smiley" data-recalc-dims="1"></p>
<p> </p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://aghaynes.wordpress.com/2018/12/05/extract-data-from-a-png-tiff/"> R – Insights of a PhD</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/BTlXITP07EU" height="1"></a></div>