How to create Hans Rosling’s famous animated bubble chart

<p>In my earlier days of learning to code, I decided that I&rsquo;d like to try to create Hans Rosling&rsquo;s Gapminder bubble chart &mdash; made famous by his hugely entertaining lectures and TED talks &mdash; 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&rsquo;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&nbsp;<code>wbstats</code>&nbsp;package in R which I had never known about before. So I&rsquo;m sharing it here.</p> <p>If you can&rsquo;t be bothered reading this, you can go straight to the code on&nbsp;<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&rsquo;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&rsquo;ll need the following R packages for this:&nbsp;<code>dplyr</code>,&nbsp;<code>ggplot2</code>,&nbsp;<code>gganimate</code>,&nbsp;<code>viridis</code>&nbsp;to help with color, and&nbsp;<code>wbstats</code>&nbsp;to get the data from the World Bank. If you want it to look exactly like mine, you may also need to install the&nbsp;<code>Oswald</code>&nbsp;font family from Google fonts, but this is not critical.</p> <p><a href="http://Read More">http://Read More</a></p>