Convenient access to Gapminder’s datasets from R
[This article was first published on factbased, 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.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
In April, Hans Rosling examined the influence of religion on fertility. I used R to replicate a graphic of his talk:
> library(datamart) > gm <- gapminder() > #queries(gm) > # > # babies per woman > tmp <- query(gm, "TotalFertilityRate") > babies <- as.vector(tmp["2008"]) > names(babies) <- names(tmp) > babies <- babies[!is.na(babies)] > countries <- names(babies) > # > # income per capita, PPP adjusted > tmp <- query(gm, "IncomePerCapita") > income <- as.vector(tmp["2008"]) > names(income) <- names(tmp) > income <- income[!is.na(income)] > countries <- intersect(countries, names(income)) > # > # religion > tmp <- query(gm, "MainReligion") > religion <- tmp[,"Group"] > names(religion) <- tmp[,"Entity"] > religion[religion==""] <- "unknown" > colcodes <- c( + Christian="blue", + "Eastern religions"="red", + Muslim="green", "unknown"="grey" + ) > countries <- intersect(countries, names(religion)) > # > # plot > par(mar=c(4,4,0,0)+0.1) > plot( + x=income[countries], + y=babies[countries], + col=colcodes[religion[countries]], + log="x", + xlab="Income per Person, PPP-adjusted", + ylab="Babies per Woman" + ) > legend( + "topright", + legend=names(colcodes), + fill=colcodes, + border=colcodes + )
One of the points Rosling wanted to make is: Religion has no or very little influence on fertility, but economic welfare has. I wonder if demographs agree and take this economic effect into account.
If you want to know more about that gapminder
function and that query
method, read on.
To leave a comment for the author, please follow the link and comment on their blog: factbased.
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.