<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/mapping-efsas-food-consumption-data-with-tmap-2/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://behrica.github.com//blog//2017/10/food-consumption-tutorial.html"> Carsten's blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h1>Disclaimer</h1>
<p><em>The opinions expressed in the article are those of the author(s) only,<br>
and may not necessarily represent the views of EFSA or of any other EU<br>
Institution or body.</em></p>
<h1>EFSA’s food consumption data</h1>
<p>The European Food Safety Authority collects food consumption data from all EU countries and and integrates them in their database. The data is based on country specific surveys, in which individuals get interviewed about their food consumption habits. This data is used for EFSA’s risk assessments as part of the exposure assessment.</p>
<h1>Accessing the data</h1>
<p>The data is available from EFSA’s website <a rel="nofollow" href="http://www.efsa.europa.eu/en/food-consumption/comprehensive-database" target="_blank">http://www.efsa.europa.eu/en/food-consumption/comprehensive-database</a> in form of Excel files.</p>
<p>I selected for this tutorial the file of the “Chronic food consumption statistics” – “grams per day” – “all subjects”.</p>
<p>The following code reads the data from the EFSA website and writes it to a local file.<br>
The file contains 4 sheets and we select the last one, which contains data on the lowest foodex level 4.</p>
<p>First download and cache it,</p>
<figure>
<pre><code data-lang="r"><span>if</span><span> </span><span>(</span><span>!</span><span>file.exists</span><span>(</span><span>&quot;chronicgdaytotpop.xlsx&quot;</span><span>))</span><span>
</span><span>download.file</span><span>(</span><span>&quot;http://www.efsa.europa.eu/sites/default/files/chronicgdaytotpop.xlsx&quot;</span><span>,</span><span>&quot;chronicgdaytotpop.xlsx&quot;</span><span>)</span></code></pre>
</figure>
<p>and the read it into R. The I fix a different spelling in the data versus the shape files to be<br>
used later for the map.</p>
<figure>
<pre><code data-lang="r"><span>data</span><span> </span><span>&lt;-</span><span> </span><span>read_excel</span><span>(</span><span>&quot;./chronicgdaytotpop.xlsx&quot;</span><span>,</span><span>&quot;L4_All_subjects_g_day&quot;</span><span>,</span><span>skip</span><span>=</span><span>2</span><span>)</span><span> </span><span>names</span><span>(</span><span>data</span><span>)</span><span> </span><span>&lt;-</span><span> </span><span>gsub</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>names</span><span>(</span><span>data</span><span>),</span><span>
</span><span>pattern</span><span> </span><span>=</span><span> </span><span>&quot;[[:space:]]|[[:punct:]]&quot;</span><span>,</span><span>
</span><span>replacement</span><span> </span><span>=</span><span> </span><span>&quot;_&quot;</span><span>,</span><span>
</span><span>perl</span><span> </span><span>=</span><span> </span><span>F</span><span>)</span><span>
</span><span>data</span><span> </span><span>&lt;-</span><span> </span><span>data</span><span> </span><span>%>%</span><span>
</span><span>fixCountries</span></code></pre>
</figure>
<h1>Description of data</h1>
<p>The data is organised ‘per country’, ‘per survey’,’per population class’ and ‘per food group’.<br>
The food classification follows the Foodex<sup><a rel="nofollow" href="https://behrica.github.com//blog//2017/10/food-consumption-tutorial.html#fn:1" target="_blank">1</a></sup> standard developed by EFSA, which is a hierarchical system for classifying food.<br>
The current data set contains the most detailed foodex levels (3 and 4)</p>
<p>The ‘Mean’ column contains then the mean consumption in grams per day of this food among the participants of the survey. Additionally to the mean other statistics about the distribution of the food intake are given (standard deviation, percentiles)</p>
<p>We can interpret a single row, such as:</p>
<figure>
<pre><code data-lang="r"><span>data</span><span> </span><span>%>%</span><span> </span><span>filter</span><span>(</span><span>Foodex_L4</span><span> </span><span>==</span><span> </span><span>'Couscous'</span><span>)</span><span> </span><span>%>%</span><span> </span><span>filter</span><span>(</span><span>row_number</span><span>()</span><span>==</span><span>1</span><span>)</span><span> </span><span>%>%</span><span> </span><span>glimpse</span></code></pre>
</figure>
<figure>
<pre><code data-lang="text">## Observations: 1
## Variables: 17
## $ Country      </code></pre></figure>