Skip to content

Instantly share code, notes, and snippets.

@mages
Last active December 15, 2015 01:38
Show Gist options
  • Save mages/5180860 to your computer and use it in GitHub Desktop.
Save mages/5180860 to your computer and use it in GitHub Desktop.
World Bank data demo
# Thanks to John Maindonald
library(WDI)
indnams <- c("fertility.rate", "life.expectancy",
"population", "GDP.per.capita.Current.USD",
"15.to.25.yr.female.literacy")
inds <- c('SP.DYN.TFRT.IN','SP.DYN.LE00.IN',
'SP.POP.TOTL','NY.GDP.PCAP.CD',
'SE.ADT.1524.LT.FE.ZS')
wdiData <- WDI(country="all", indicator=inds,
start=1960, end=format(Sys.Date(), "%Y"),
extra=TRUE)
colnum <- match(inds, names(wdiData))
names(wdiData)[colnum] <- indnams
## Create a motion chart
library(googleVis)
WorldBank <- droplevels(subset(wdiData,
!region %in% "Aggregates"))
M <- gvisMotionChart(WorldBank,
idvar="country", timevar="year",
xvar="life.expectancy",
yvar="fertility.rate",
colorvar="region",
sizevar="population",
options=list(width=550, height=500))
## Display the chart in the browser
plot(M)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment