How to create Hans Rosling’s famous animated bubble chart
<p>In my earlier days of learning to code, I decided that I’d like to try to create Hans Rosling’s Gapminder bubble chart — made famous by his hugely entertaining lectures and TED talks — from scratch in R.</p>
<p>I had a few criteria in mind as I proceeded:</p>
<ol>
<li>Can I do it using economic data straight from the World Bank source, without needing to use local data files or package data which may not be up to date?</li>
<li>Can I make it look reasonably close to how Rosling’s chart looked?</li>
<li>Is it possible do to it in a single piped command in R?</li>
</ol>
<p>I was able to fulfil all my criteria, and having done so I realized that this was a great little learning exercise for those who wish to work more in animated graphics, and also made me aware of the <code>wbstats</code> package in R which I had never known about before. So I’m sharing it here.</p>
<p>If you can’t be bothered reading this, you can go straight to the code on <a href="https://github.com/keithmcnulty/hans_rosling_bubble/blob/master/rosling.R" rel="noopener ugc nofollow" target="_blank">Github</a>.</p>
<p>As a precautionary note, this isn’t the shortest way of doing it. You can do it in fewer characters, but this will mean not namespacing functions (which I always try to do for the benefit of code readers), or pulling data from intermediate sources. But I think this is a nice, independent and future-proof approach which is clean and efficient.</p>
<h2>Setting up and grabbing data</h2>
<p>You’ll need the following R packages for this: <code>dplyr</code>, <code>ggplot2</code>, <code>gganimate</code>, <code>viridis</code> to help with color, and <code>wbstats</code> to get the data from the World Bank. If you want it to look exactly like mine, you may also need to install the <code>Oswald</code> font family from Google fonts, but this is not critical.</p>
<p><a href="http://Read More">http://Read More</a></p>