In April, Hans Rosling examined the influence of religion on fertility. I used R to replicate a graphic of his talk:
> <span>library</span>(datamart)
> gm <- <span>gapminder</span>()
> <span>#queries(gm)</span>
> <span>#</span>
> <span># babies per woman</span>
> tmp <- <span>query</span>(gm, <span>"TotalFertilityRate"</span>)
> babies <- <span>as.vector</span>(tmp[<span>"2008"</span>])
> <span>names</span>(babies) <- <span>names</span>(tmp)
> babies <- babies[!<span>is.na</span>(babies)]
> countries <- <span>names</span>(babies)
> <span>#</span>
> <span># income per capita, PPP adjusted</span>
> tmp <- <span>query</span>(gm, <span>"IncomePerCapita"</span>)
> income <- <span>as.vector</span>(tmp[<span>"2008"</span>])
> <span>names</span>(income) <- <span>names</span>(tmp)
> income <- income[!<span>is.na</span>(income)]
> countries <- <span>intersect</span>(countries, <span>names</span>(income))
> <span>#</span>
> <span># religion</span>
> tmp <- <span>query</span>(gm, <span>"MainReligion"</span>)
> religion <- tmp[,<span>"Group"</span>]
> <span>names</span>(religion) <- tmp[,<span>"Entity"</span>]
> religion[religion==<span>""</span>] <- <span>"unknown"</span>
> colcodes <- <span>c</span>(
+ <span>Christian=</span><span>"blue"</span>,
+ <span>"Eastern religions"</span>=<span>"red"</span>,
+ <span>Muslim=</span><span>"green"</span>, <span>"unknown"</span>=<span>"grey"</span>
+ )
> countries <- <span>intersect</span>(countries, <span>names</span>(religion))
> <span>#</span>
> <span># plot</span>
> <span>par</span>(<span>mar=</span><span>c</span>(<span>4</span>,<span>4</span>,<span>0</span>,<span>0</span>)+<span>0.1</span>)
> <span>plot</span>(
+ <span>x=</span>income[countries],
+ <span>y=</span>babies[countries],
+ <span>col=</span>colcodes[religion[countries]],
+ <span>log=</span><span>"x"</span>,
+ <span>xlab=</span><span>"Income per Person, PPP-adjusted"</span>,
+ <span>ylab=</span><span>"Babies per Woman"</span>
+ )
> <span>legend</span>(
+ <span>"topright"</span>,
+ <span>legend=</span><span>names</span>(colcodes),
+ <span>fill=</span>colcodes,
+ <span>border=</span>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 ...