Japans ageing population, animated with R

[This article was first published on Revolutions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The US Census makes a number of its databases available to developers via the Census API. One of those databases is the International Data Base, in which the Census department provides historic demographic breakdowns (population by age and sex) for many countries, along with projections through 2050. Kyle Walker created the R package idbr (currently only available on GitHub) to make it easy to download these datasets using R, and used it to create the animation below showing Japan's demographic change since 1990. As you can see, the Census Bureau predicts that this ageing of the population will only intensify over time. Note the ever-declining population of babies being added at the bottom of the chart. In fact, Japan's population declined for the first time just this year.


Kyle used ggplot's geom_bar plot to visulize the population pyramid, and rendered it using the Economist theme from the ggthemes package. To run the code, you'll need to request a Census API key (you just need to provide your company and email address, and you'll have one in minutes), and install ImageMagick to support the animation package. You can see Kyle's original code below (I adapted it slightly to show the historical demographics since 1990 and to resize the animation for this blog post.)

For more on Kyle's idbr package, check out the GitHub repository linked below.

Github (walkerke): idbr, An R interface to the US Census Bureau International Data Base API (via the author)

To leave a comment for the author, please follow the link and comment on their blog: Revolutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)