<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/how-not-to-make-an-evergreen-review-graph/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://maelle.github.io/2017/05/14/evergreenreviewgraph/"> Maëlle</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>In this post I am inspired by two tweets, mainly <a target="_blank" rel="nofollow" href="https://twitter.com/noamross/status/843913486266777605">this one</a> and also <a target="_blank" rel="nofollow" href="https://twitter.com/polesasunder/status/824639612354228225">this one</a>. Since the total number of articles every year is increasing, no matter which subject you choose, the curve representing number of articles as a function of year of publication will probably look exponential, so one should not use such graphs to impress readers. At least I’m not impressed, I’m more amused by such graphs now that there’s a hashtag for them.</p>
<p>I shall use an rOpenSci package for getting some data about number of articles about a query term, and to do a graph that’s not an evergreen review graph!</p>
<p><span></span></p>
<h1>Getting some numbers of articles</h1>
<p>For this I’ll use one of the <a target="_blank" rel="nofollow" href="https://ropensci.org/packages/#literature">numerous rOpenSci packages simplifying your programmatic access to scientific literature</a>, <a target="_blank" rel="nofollow" href="https://github.com/ropensci/europepmc"><code>europepmc</code></a> which is an interface to <a target="_blank" rel="nofollow" href="https://europepmc.org/">Europe PMC</a>, “Search worldwide, life-sciences literature”. The package includes a cool function called <code>epmc_profile</code> that gives you the number of hits for a given query. Perfect!</p>
<p>Now my goal is to get the number of hits by year for a search term but also the total number of hits in order to put things into perspective. I had no idea how to write a proper Europe PMC query so I went to the <a target="_blank" rel="nofollow" href="https://europepmc.org/advancesearch">advanced search page</a> and made queries there in order to learn enough words of this language to get what I needed. Indeed, when you create a query by clicking there and then hit search, the URL contains the query as you need it to be written for using the <code>europepmc</code> package.</p>
<p>For each query <code>epmc_profile</code> returns hits by source and type, but I’m interested in all hits, including e.g. books, so that’s what I’ll use.</p>
<p>Let’s write functions!</p>
<div>
<pre><code><span>library</span><span>(</span><span>&quot;europepmc&quot;</span><span>)</span><span>
</span><span>find_hits</span><span> </span><span>&lt;-</span><span> </span><span>function</span><span>(</span><span>query_term</span><span>){</span><span>
</span><span>years</span><span> </span><span>&lt;-</span><span> </span><span>1975</span><span>:</span><span>2016</span><span>
</span><span>results</span><span> </span><span>&lt;-</span><span> </span><span>purrr</span><span>::</span><span>map</span><span>(</span><span>years</span><span>,</span><span> </span><span>find_hits_by_year</span><span>,</span><span> </span><span>query_term</span><span> </span><span>=</span><span> </span><span>query_term</span><span>)</span><span>
</span><span>dplyr</span><span>::</span><span>bind_rows</span><span>(</span><span>results</span><span>)</span><span>
</span><span>}</span><span>
</span><span>find_hits_by_year</span><span> </span><span>&lt;-</span><span> </span><span>function</span><span>(</span><span>year</span><span>,</span><span> </span><span>query_term</span><span>){</span><span>
</span><span>queryforall</span><span> </span><span>&lt;-</span><span> </span><span>paste0</span><span>(</span><span>'(FIRST_PDATE:['</span><span>,</span><span> </span><span>year</span><span>,</span><span> </span><span>'-01-01+TO+'</span><span>,</span><span> </span><span>year</span><span>,</span><span> </span><span>'-12-31])'</span><span>)</span><span>
</span><span>all_hits</span><span> </span><span>&lt;-</span><span> </span><span>as.numeric</span><span>(</span><span>epmc_profile</span><span>(</span><span>queryforall</span><span>)</span><span>$</span><span>pubType</span><span>[</span><span>1</span><span>,</span><span> </span><span>2</span><span>])</span><span>
</span><span>queryforterm</span><span> </span><span>&lt;-</span><span> </span><span>paste0</span><span>(</span><span>'(FIRST_PDATE:['</span><span>,</span><span> </span><span>year</span><span>,</span><span> </span><span>'-01-01+TO+'</span><span>,</span><span> </span><span>year</span><span>,</span><span> </span><span>'-12-31]) AND &quot;'</span><span>,</span><span> </span><span>query_term</span><span>,</span><span> </span><span>'&quot;'</span><span>)</span><span>
</span><span>term_hits</span><span> </span><span>&lt;-</span><span> </span><span>as.numeric</span><span>(</span><span>epmc_profile</span><span>(</span><span>queryforterm</span><span>)</span><span>$</span><span>pubType</span><span>[</span><span>1</span><span>,</span><span> </span><span>2</span><span>])</span><span>
</span><span>return</span><span>(</span><span>tibble</span><span>::</span><span>tibble</span><span>(</span><span>year</span><span> </span><span>=</span><span> </span><span>year</span><span>,</span><span> </span><span>all_hits</span><span> </span><span>=</span><span> </span><span>all_hits</span><span>,</span><span> </span><span>term_hits</span><span> </span><span>=</span><span> </span><span>term_hits</span><span>))</span><span>
</span><span>}</span><span>
</span></code></pre>
</div>
<p>Now let’s apply the function to one term. I’ll choose Malaria because it’s the term used in one of <code>europepmc</code> examples.</p>
<div>
<pre><code><span>malaria_fame</span><span> </span><span>&lt;-</span><span> </span><span>find_hits</span><span>(</span><span>&quot;malaria&quot;</span><span>)</span><span>
</span><span>library</span><span>(</span><span>&quot;magrittr&quot;</span><span>)</span><span>
</span><span>head</span><span>(</span><span>malaria_fame</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>knitr</span><span>::</span><span>kable</span><span>()</span><span>
</span></code></pre>
</div>
<table>
<thead>
<tr>
<th>year</th>
<th>all_hits</th>
<th>term_hits</th>
</tr>
</thead>
<tbody>
<tr>
<td>1975</td>
<td>252386</td>
<td>394</td>
</tr>
<tr>
<td>1976</td>
<td>259044</td>
<td>425</td>
</tr>
<tr>
<td>1977</td>
<td>266538</td>
<td>432</td>
</tr>
<tr>
<td>1978</td>
<td>279160</td>
<td>475</td>
</tr>
<tr>
<td>1979</td>
<td>294491</td>
<td>516</td>
</tr>
<tr>
<td>1980</td>
<td>295471</td>
<td>443</td>
</tr>
</tbody>
</table>
<p>Obviously in a review about malaria research one might have a more precise query, and one might want to compare the number of hits for that query to other precise queries, but in this simple example I’m just comparing the number of hits of one term to the number of all hits, Note that one could also make no graph about number of hits over time, shocking I now! I’ll most certainly won’t do no graph here though, now that I collected the data.</p>
<h1>Making nice plots</h1>
<p>I’ll do as Lucy in <a target="_blank" rel="nofollow" href="http://livefreeordichotomize.com/2017/03/04/xkcd-thank-you-note/">this blog post</a> and use the <code>xkcd</code> package. As noted by Lucy, <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/xkcd/vignettes/xkcd-intro.pdf">its vignette</a> is great. I might have done something wrong but after downloading the file with the xkcd font I had to copy-paste it myself in the fonts folder of Windows. The syntax of the xkcdman is a bit long but following the examples I could get what I wanted.</p>
<div>
<pre><code><span>library</span><span>(</span><span>&quot;xkcd&quot;</span><span>)</span><span>
</span><span>library</span><span>(</span><span>&quot;ggplot2&quot;</span><span>)</span><span>
</span><span>library</span><span>(</span><span>&quot;extrafont&quot;</span><span>)</span><span>
</span><span>xrange</span><span> </span><span>&lt;-</span><span> </span><span>range</span><span>(</span><span>malaria_fame</span><span>$</span><span>year</span><span>)</span><span>
</span><span>yrange</span><span> </span><span>&lt;-</span><span> </span><span>range</span><span>(</span><span>malaria_fame</span><span>$</span><span>term_hits</span><span>)</span><span>
</span><span>ratioxy</span><span> </span><span>&lt;-</span><span> </span><span>diff</span><span>(</span><span>xrange</span><span>)</span><span>/</span><span>diff</span><span>(</span><span>yrange</span><span>)</span><span>
</span><span>mapping</span><span> </span><span>&lt;-</span><span> </span><span>aes</span><span>(</span><span>x</span><span>=</span><span>x</span><span>,</span><span>
</span><span>y</span><span>=</span><span>y</span><span>,</span><span>
</span><span>scale</span><span>=</span><span>scale</span><span>,</span><span>
</span><span>ratioxy</span><span>=</span><span>ratioxy</span><span>,</span><span>
</span><span>angleofspine</span><span> </span><span>=</span><span> </span><span>angleofspine</span><span>,</span><span>
</span><span>anglerighthumerus</span><span> </span><span>=</span><span> </span><span>anglerighthumerus</span><span>,</span><span>
</span><span>anglelefthumerus</span><span> </span><span>=</span><span> </span><span>anglelefthumerus</span><span>,</span><span>
</span><span>anglerightradius</span><span> </span><span>=</span><span> </span><span>anglerightradius</span><span>,</span><span>
</span><span>angleleftradius</span><span> </span><span>=</span><span> </span><span>angleleftradius</span><span>,</span><span>
</span><span>anglerightleg</span><span> </span><span>=</span><span> </span><span>anglerightleg</span><span>,</span><span>
</span><span>angleleftleg</span><span> </span><span>=</span><span> </span><span>angleleftleg</span><span>,</span><span>
</span><span>angleofneck</span><span> </span><span>=</span><span> </span><span>angleofneck</span><span>)</span><span>
</span><span>dataman</span><span> </span><span>&lt;-</span><span> </span><span>data.frame</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>1985</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>4000</span><span>,</span><span>
</span><span>scale</span><span> </span><span>=</span><span> </span><span>1000</span><span>,</span><span>
</span><span>ratioxy</span><span> </span><span>=</span><span> </span><span>ratioxy</span><span>,</span><span>
</span><span>angleofspine</span><span> </span><span>=</span><span> </span><span>-</span><span> </span><span>pi</span><span> </span><span>/</span><span> </span><span>2</span><span>,</span><span>
</span><span>anglerighthumerus</span><span> </span><span>=</span><span> </span><span>4</span><span>*</span><span>pi</span><span>/</span><span>6</span><span>,</span><span>
</span><span>anglelefthumerus</span><span> </span><span>=</span><span> </span><span>pi</span><span>/</span><span>6</span><span>,</span><span>
</span><span>anglerightradius</span><span> </span><span>=</span><span> </span><span>pi</span><span>/</span><span>2</span><span>,</span><span>
</span><span>angleleftradius</span><span> </span><span>=</span><span> </span><span>pi</span><span>/</span><span>2</span><span>,</span><span>
</span><span>angleleftleg</span><span> </span><span>=</span><span> </span><span>3</span><span>*</span><span>pi</span><span>/</span><span>2</span><span> </span><span>+</span><span> </span><span>pi</span><span> </span><span>/</span><span> </span><span>12</span><span> </span><span>,</span><span>
</span><span>anglerightleg</span><span> </span><span>=</span><span> </span><span>3</span><span>*</span><span>pi</span><span>/</span><span>2</span><span> </span><span>-</span><span> </span><span>pi</span><span> </span><span>/</span><span> </span><span>12</span><span>,</span><span>
</span><span>angleofneck</span><span> </span><span>=</span><span> </span><span>3</span><span> </span><span>*</span><span> </span><span>pi</span><span> </span><span>/</span><span> </span><span>2</span><span> </span><span>-</span><span> </span><span>pi</span><span>/</span><span>10</span><span>)</span><span>
</span><span>ggplot</span><span>(</span><span>malaria_fame</span><span>)</span><span> </span><span>+</span><span>
</span><span>geom_point</span><span>(</span><span>aes</span><span>(</span><span>year</span><span>,</span><span> </span><span>term_hits</span><span>))</span><span> </span><span>+</span><span>
</span><span>xlab</span><span>(</span><span>&quot;Time in years&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>ylab</span><span>(</span><span>&quot;Number of hits for Malaria&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>xkcdaxis</span><span>(</span><span>xrange</span><span> </span><span>=</span><span> </span><span>xrange</span><span>,</span><span>
</span><span>yrange</span><span> </span><span>=</span><span> </span><span>yrange</span><span>)</span><span> </span><span>+</span><span>
</span><span>theme</span><span>(</span><span>text</span><span> </span><span>=</span><span> </span><span>element_text</span><span>(</span><span>size</span><span> </span><span>=</span><span> </span><span>16</span><span>,</span><span> </span><span>family</span><span> </span><span>=</span><span> </span><span>&quot;xkcd&quot;</span><span>))</span><span> </span><span>+</span><span>
</span><span>xkcdman</span><span>(</span><span>mapping</span><span>,</span><span>dataman</span><span>)</span><span> </span><span>+</span><span>
</span><span>annotate</span><span>(</span><span>&quot;text&quot;</span><span>,</span><span> </span><span>family</span><span> </span><span>=</span><span> </span><span>&quot;xkcd&quot;</span><span>,</span><span> </span><span>x</span><span> </span><span>=</span><span> </span><span>1985</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>4800</span><span>,</span><span> </span><span>label</span><span> </span><span>=</span><span> </span><span>&quot;Oops!\n I made an evergreen review graph!&quot;</span><span>,</span><span> </span><span>size</span><span> </span><span>=</span><span> </span><span>6</span><span>)</span><span>
</span></code></pre>
</div>
<p><img alt="plot of chunk unnamed-chunk-3" src="https://i1.wp.com/maelle.github.io/figure/source/2017-05-14-evergreenreviewgraph/unnamed-chunk-3-1.png?w=456" data-recalc-dims="1"></p>
<p>Ok that one is not really the one I’d advise you to submit to any journal. Let’s do better.</p>
<div>
<pre><code><span>malaria_fame</span><span> </span><span>&lt;-</span><span> </span><span>dplyr</span><span>::</span><span>mutate</span><span>(</span><span>malaria_fame</span><span>,</span><span> </span><span>prop</span><span> </span><span>=</span><span> </span><span>term_hits</span><span>/</span><span>all_hits</span><span>)</span><span>
</span><span>xrange</span><span> </span><span>&lt;-</span><span> </span><span>range</span><span>(</span><span>malaria_fame</span><span>$</span><span>year</span><span>)</span><span>
</span><span>yrange</span><span> </span><span>&lt;-</span><span> </span><span>range</span><span>(</span><span>malaria_fame</span><span>$</span><span>prop</span><span>)</span><span>
</span><span>ratioxy</span><span> </span><span>&lt;-</span><span> </span><span>diff</span><span>(</span><span>xrange</span><span>)</span><span>/</span><span>diff</span><span>(</span><span>yrange</span><span>)</span><span>
</span><span>dataman</span><span> </span><span>&lt;-</span><span> </span><span>data.frame</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>1985</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>0.005</span><span>,</span><span>
</span><span>scale</span><span> </span><span>=</span><span> </span><span>0.001</span><span>,</span><span>
</span><span>ratioxy</span><span> </span><span>=</span><span> </span><span>ratioxy</span><span>,</span><span>
</span><span>angleofspine</span><span> </span><span>=</span><span> </span><span>-</span><span> </span><span>pi</span><span> </span><span>/</span><span> </span><span>2</span><span>,</span><span>
</span><span>anglerighthumerus</span><span> </span><span>=</span><span> </span><span>-</span><span>pi</span><span>/</span><span>6</span><span>,</span><span>
</span><span>anglelefthumerus</span><span> </span><span>=</span><span> </span><span>pi</span><span> </span><span>+</span><span> </span><span>pi</span><span>/</span><span>6</span><span>,</span><span>
</span><span>anglerightradius</span><span> </span><span>=</span><span> </span><span>0</span><span>,</span><span>
</span><span>angleleftradius</span><span> </span><span>=</span><span> </span><span>0</span><span>,</span><span>
</span><span>angleleftleg</span><span> </span><span>=</span><span> </span><span>3</span><span>*</span><span>pi</span><span>/</span><span>2</span><span> </span><span>+</span><span> </span><span>pi</span><span> </span><span>/</span><span> </span><span>12</span><span> </span><span>,</span><span>
</span><span>anglerightleg</span><span> </span><span>=</span><span> </span><span>3</span><span>*</span><span>pi</span><span>/</span><span>2</span><span> </span><span>-</span><span> </span><span>pi</span><span> </span><span>/</span><span> </span><span>12</span><span>,</span><span>
</span><span>angleofneck</span><span> </span><span>=</span><span> </span><span>3</span><span> </span><span>*</span><span> </span><span>pi</span><span> </span><span>/</span><span> </span><span>2</span><span> </span><span>-</span><span> </span><span>pi</span><span>/</span><span>10</span><span>)</span><span>
</span><span>ggplot</span><span>(</span><span>malaria_fame</span><span>)</span><span> </span><span>+</span><span>
</span><span>geom_point</span><span>(</span><span>aes</span><span>(</span><span>year</span><span>,</span><span> </span><span>prop</span><span>))</span><span> </span><span>+</span><span>
</span><span>xlab</span><span>(</span><span>&quot;Time in years&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>ylab</span><span>(</span><span>&quot;No. of hits for Malaria divided by total no. of hits&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>xkcdaxis</span><span>(</span><span>xrange</span><span> </span><span>=</span><span> </span><span>xrange</span><span>,</span><span>
</span><span>yrange</span><span> </span><span>=</span><span> </span><span>yrange</span><span>)</span><span> </span><span>+</span><span>
</span><span>theme</span><span>(</span><span>text</span><span> </span><span>=</span><span> </span><span>element_text</span><span>(</span><span>size</span><span> </span><span>=</span><span> </span><span>16</span><span>,</span><span> </span><span>family</span><span> </span><span>=</span><span> </span><span>&quot;xkcd&quot;</span><span>))</span><span> </span><span>+</span><span>
</span><span>xkcdman</span><span>(</span><span>mapping</span><span>,</span><span>dataman</span><span>)</span><span> </span><span>+</span><span>
</span><span>annotate</span><span>(</span><span>&quot;text&quot;</span><span>,</span><span> </span><span>family</span><span> </span><span>=</span><span> </span><span>&quot;xkcd&quot;</span><span>,</span><span> </span><span>x</span><span> </span><span>=</span><span> </span><span>1985</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>0.006</span><span>,</span><span> </span><span>label</span><span> </span><span>=</span><span> </span><span>&quot;Now that's more interesting!&quot;</span><span>,</span><span> </span><span>size</span><span> </span><span>=</span><span> </span><span>6</span><span>)</span><span>
</span></code></pre>
</div>
<p><img alt="plot of chunk unnamed-chunk-4" src="https://i0.wp.com/maelle.github.io/figure/source/2017-05-14-evergreenreviewgraph/unnamed-chunk-4-1.png?w=456" data-recalc-dims="1"></p>
<p>Okay friends so that one is a bit more interesting, and I’m more convinced my its shape. I’d like to know whether there really was a malaria research peak, but only waiting for a few years will bring me the answer! It’d also be interesting to compare the fate of other diseases, and to put that in context with some domain knowledge. But that’d be a subject for another study, now at least you know how to not make an evergreen review graph!</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="http://maelle.github.io/2017/05/14/evergreenreviewgraph/"> Maëlle</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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/DXVGSeiQrVY"></a></div>