<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/yet-the-worst-olympic-chart/"></div></div><div><a data-url="https://www.r-bloggers.com/yet-the-worst-olympic-chart/" data-counturl="https://www.r-bloggers.com/yet-the-worst-olympic-chart/" data-count="horizontal" data-text="Yet the Worst Olympic Chart" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://danielmarcelino.github.io/blog/2016/yet-the-worst-olympic-chart.html"> Daniel's Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Ah, the numbers! The Olympic Games are back in high style in Rio. Despite Brazil’s sluggish economy and unfulfilled promises for this Summer Olympic Games, I’d say, my expectations were met yesterday with such a beautiful opening ceremony. Let’s follow the competition over the next few days–the pressure to perform has only just begun.</p>
<p>One interesting aspect about the Olympic games is the way people around the globe cover it. In fact, several news houses are quite excited about telling predictions and showing medals rankings of all sort, starting soon today. Surprisingly, yesterday my eyes catch a stacked bar chart by <a target="_blank" href="http://www.nbcolympics.com/">NBC</a> with a really bad visualization taste. It’s so inaccurate that it deserves the title of <em>Worst Olympic Chart</em>.</p>
<p><img title="center" alt="center" src="https://i1.wp.com/danielmarcelino.github.io/img/08-06-2016-yet-the-worst-olympic-chart/NBC-olympic-medals.PNG?w=456" data-recalc-dims="1"></p>
<p>The colors are fine, but the dimensions are simply misleading. How have the 976 USA Olympic gold medals been given less length in the plot than 797 Russia’s medals (silver and bronze), or all 777.5 medals of Great Britain? Yep, that’s right. One can get half a medal by tying for a placement. Anyway, I believe it shouldn’t be that difficult to make a decent-looking, yet accurate plot for readers. Perhaps, the worst is yet to come.</p>
<h4>Top-3 all-time Olympic medals</h4>
<p><img title="center" alt="center" src="https://i0.wp.com/danielmarcelino.github.io/img/08-06-2016-yet-the-worst-olympic-chart/unnamed-chunk-2-1.png?w=456" data-recalc-dims="1"></p>
<h4>The data points</h4>
<figure>
<pre><code data-lang="r"><span>library</span><span>(</span><span>dplyr</span><span>)</span><span>
</span><span>country</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>rep</span><span>(</span><span>'US'</span><span>,</span><span>3</span><span>),</span><span>rep</span><span>(</span><span>'RUS'</span><span>,</span><span>3</span><span>),</span><span>rep</span><span>(</span><span>'GB'</span><span>,</span><span>3</span><span>))</span><span>
</span><span>Medal</span><span> </span><span>=</span><span> </span><span>rep</span><span>(</span><span>c</span><span>(</span><span>'Gold'</span><span>,</span><span>'Silver'</span><span>,</span><span>'Bronze'</span><span>),</span><span>3</span><span>)</span><span>
</span><span>counts</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>976.0</span><span>,</span><span> </span><span>759.5</span><span>,</span><span> </span><span>668.5</span><span>,</span><span> </span><span>440.0</span><span>,</span><span> </span><span>357.0</span><span>,</span><span>326.0</span><span>,</span><span> </span><span>233.5</span><span>,</span><span> </span><span>272.5</span><span>,</span><span> </span><span>271.5</span><span>)</span><span>
</span><span>Olympics</span><span> </span><span>=</span><span> </span><span>as.data.frame</span><span>(</span><span>
</span><span>cbind</span><span>(</span><span>country</span><span>,</span><span>
</span><span>Medal</span><span>,</span><span>
</span><span>counts</span><span>))</span><span>
</span><span>Olympics</span><span>$</span><span>counts</span><span> </span><span>=</span><span> </span><span>as.numeric</span><span>(</span><span>levels</span><span>(</span><span>Olympics</span><span>$</span><span>counts</span><span>))[</span><span>Olympics</span><span>$</span><span>counts</span><span>]</span><span>
</span><span>Olympics</span><span>$</span><span>Medal</span><span> </span><span>&lt;-</span><span> </span><span>factor</span><span>(</span><span>Olympics</span><span>$</span><span>Medal</span><span>,</span><span>levels</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>'Gold'</span><span>,</span><span>'Silver'</span><span>,</span><span>'Bronze'</span><span>))</span><span>
</span><span>Olympics</span><span> </span><span>&lt;-</span><span> </span><span>Olympics</span><span> </span><span>%>%</span><span> </span><span>group_by</span><span>(</span><span>country</span><span>)</span><span> </span><span>%>%</span><span> </span><span>mutate</span><span>(</span><span>mid_y</span><span>=</span><span>cumsum</span><span>(</span><span>counts</span><span>)</span><span> </span><span>-</span><span> </span><span>0.5</span><span>*</span><span>counts</span><span>)</span></code></pre>
</figure>
<h4>Do the plot</h4>
<figure>
<pre><code data-lang="r"><span>library</span><span>(</span><span>ggplot2</span><span>)</span><span>
</span><span>library</span><span>(</span><span>SciencesPo</span><span>)</span><span> </span><span># for the theme.
</span><span>
</span><span>g</span><span> </span><span>&lt;-</span><span> </span><span>ggplot</span><span>(</span><span>Olympics</span><span>,</span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>country</span><span>,</span><span> </span><span>y</span><span>=</span><span>counts</span><span>,</span><span> </span><span>fill</span><span> </span><span>=</span><span> </span><span>Medal</span><span>))</span><span> </span><span>g</span><span> </span><span>&lt;-</span><span> </span><span>g</span><span> </span><span>+</span><span> </span><span>geom_bar</span><span>(</span><span>stat</span><span> </span><span>=</span><span> </span><span>'identity'</span><span>)</span><span>
</span><span>g</span><span> </span><span>&lt;-</span><span> </span><span>g</span><span> </span><span>+</span><span> </span><span>scale_fill_manual</span><span>(</span><span>values</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>'#FFD700'</span><span>,</span><span>'#C0C0C0'</span><span>,</span><span>'#CD7F32'</span><span>))</span><span> </span><span>g</span><span> </span><span>&lt;-</span><span> </span><span>g</span><span> </span><span>+</span><span> </span><span>scale_y_continuous</span><span>(</span><span>limits</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>0</span><span>,</span><span> </span><span>2500</span><span>))</span><span>
</span><span>g</span><span> </span><span>&lt;-</span><span> </span><span>g</span><span> </span><span>+</span><span> </span><span>geom_text</span><span>(</span><span>aes</span><span>(</span><span>label</span><span>=</span><span>counts</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>mid_y</span><span>),</span><span> </span><span>size</span><span> </span><span>=</span><span> </span><span>3</span><span>)</span><span>
</span><span>g</span><span> </span><span>&lt;-</span><span> </span><span>g</span><span> </span><span>+</span><span> </span><span>labs</span><span>(</span><span>x</span><span>=</span><span>''</span><span>,</span><span>y</span><span>=</span><span>'Number of Medals'</span><span>,</span><span> </span><span>title</span><span>=</span><span>'Olympic Medals'</span><span>)</span><span>
</span><span>g</span><span> </span><span>&lt;-</span><span> </span><span>g</span><span> </span><span>+</span><span> </span><span>coord_flip</span><span>()</span><span> </span><span>+</span><span> </span><span>theme_scipo</span><span>(</span><span>base_size</span><span> </span><span>=</span><span> </span><span>13</span><span>)</span><span>
</span><span>g</span><span> </span><span>&lt;-</span><span> </span><span>g</span><span> </span><span>+</span><span> </span><span>no_y_gridlines</span><span>()</span><span>
</span><span>print</span><span>(</span><span>g</span><span>)</span></code></pre>
</figure>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/yet-the-worst-olympic-chart/"></div></div><div><a data-url="https://www.r-bloggers.com/yet-the-worst-olympic-chart/" data-counturl="https://www.r-bloggers.com/yet-the-worst-olympic-chart/" data-count="vertical" data-text="Yet the Worst Olympic Chart" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://danielmarcelino.github.io/blog/2016/yet-the-worst-olympic-chart.html"> Daniel's Blog</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/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=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/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/woVkAwcyVqs"></a></div>