Japans ageing population, animated with R

February 26, 2016
By

(This article was first published on Revolutions, and kindly contributed to R-bloggers)

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.

Japan_pyramid

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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

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)