Created
April 17, 2014 18:15
-
-
Save walkerke/11002398 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(WDI) | |
library(rCharts) | |
library(plyr) | |
countries <- c("AL", "AT", "BE", "BA", "BG", "HR", "CZ", "DK", "FI", "FR", "DE", "GR", | |
"HU", "IS", "IE", "IT", "NL", "NO", "PL", "PT", "RO", "RS", "SK", "SI", | |
"ES", "SE", "CH", "GB") | |
tfr <- WDI(country = countries, indicator = "SP.DYN.TFRT.IN", start = 1960, end = 2011) | |
#Clean up the data a bit | |
tfr <- rename(tfr, replace = c("SP.DYN.TFRT.IN" = "TFR")) | |
tfr$TFR <- round(tfr$TFR, 2) | |
# Create the chart | |
tfrPlot <- nPlot( | |
TFR ~ year, | |
data = tfr, | |
group = "country", | |
type = "lineChart") | |
# Add axis labels and format the tooltip | |
tfrPlot$yAxis(axisLabel = "Total fertility rate", width = 62) | |
tfrPlot$xAxis(axisLabel = "Year") | |
# Here, the 'e' parameter allows you to pass other variables to the tooltip, like 'iso2c' in this example. | |
tfrPlot$chart(tooltipContent = "#! function(key, x, y, e){ | |
return '<h3>' + key + ' (' + e.point.iso2c + ')' + '</h3>' + | |
'<p>' + y + ' in ' + x + '</p>' | |
} !#") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment