Interactive map of world population with R

Recently I have been experimenting with R’s data visualization capabilities and I wanted to test how the maps plotted with rworldmap could be made interactive through the manipulate package, part of RStudio. Interactivity can add a lot to our understanding of complex data sets, where variations happens along multiple dimensions. To get inspired on the topic you can watch this great Ted Talk by Hans Rosling: Stats that reshape your world-view.

With only few lines of R code I was able to obtain an interactive map of the world population where the displayed Year (from 1950 to 2010) can be selected through a slider.

The source data set I utilized comes from the United Nations. The link is in the source code below. I used the first Sheet in the downloaded Excel named ESTIMATES. Before saving it to CSV, I had to set the formatting of all number cells to general as the original number formatting contained spaces and, surprisingly enough, they were left in after the conversion. This confused R very much!

The charts still need some aesthetical improvement (e.g. title, legend) but the concept works fairly well. It is impressive to quickly scroll from 1950 to 2010 (you can use the right and left arrow keys for that once the focus is on the slider) to see in which countries and areas the population has been growing faster.

Next I think I am going to try some bubble charts along the inspiration provided by Rosling. Till next time!