Skip to content

Instantly share code, notes, and snippets.

@ritchieking
Last active December 15, 2015 03:39
Show Gist options
  • Save ritchieking/5195486 to your computer and use it in GitHub Desktop.
Save ritchieking/5195486 to your computer and use it in GitHub Desktop.
The growth in catholics around the world

On March 13, 2013, Jorge Mario Bergoglio became the first Latin American to head up the Vatican. As Pope Francis, he will lead a Roman Catholic church that is rapidly changing in its demographics. The data shown here, from the World Christian Database represents the absoulte growth in the number of catholics in every country in the world between 2000 and 2010. What's clear is that the biggest growth is happening in Latin America and Africa, while the biggest contraction is happening in Europe.

The code used in this block is based heavily on Mike Bostock's Bar Chart with Negative Values example.

country diff
Mexico 11048128
Philippines 9671495
Congo DR 8740279
United States 7685824
Brazil 7187750
Nigeria 5667679
Colombia 4909147
Spain 4136959
Uganda 3441907
Tanzania 3356136
Venezuela 3115925
Italy 3024351
Angola 2951473
Guatemala 2883695
South Sudan 2599618
Peru 2234819
Argentina 2117311
Malawi 2012152
China 2000000
India 1856558
Kenya 1776483
Burundi 1611525
Mozambique 1555647
Zambia 1547123
Bolivia 1526726
Madagascar 1399984
Ecuador 1319856
Canada 1196105
Rwanda 1105805
Congo 1043956
Cameroon 1029099
China 1000000
South Korea 998904
Viet Nam 978731
France 971766
Dominican Republic 965009
Paraguay 912513
Burkina Faso 904430
Cote d'Ivoire 855416
Honduras 822381
Haiti 819199
Ghana 811133
Indonesia 793255
Cuba 692988
Central African Republic 667807
Benin 634245
Chile 608248
Nicaragua 602654
Chad 575488
Zimbabwe 570722
United Arab Emirates 530000
Australia 454044
Ukraine 441357
Togo 413789
Ethiopia 413516
South Africa 412067
Panama 377179
Slovakia 335686
Saudi Arabia 307000
Ireland 285165
Timor-Leste 248302
Costa Rica 239438
Papua New Guinea 225286
Sierra Leone 211280
Switzerland 205352
Malaysia 198526
Mali 191124
Gabon 187724
Senegal 184318
Liberia 169741
Lesotho 165579
Sri Lanka 159033
Equatorial Guinea 141142
Lebanon 121788
Namibia 113616
Guinea 101127
Syria 88895
United Kingdom 87835
Qatar 84000
Greece 80918
Reunion 80000
Kuwait 72650
New Zealand 69934
Cambodia 66724
Portugal 64689
Bangladesh 62893
Thailand 62314
Myanmar 57965
Cape Verde 55109
El Salvador 55099
French Guiana 50000
Singapore 48553
Sweden 46015
Mauritius 45879
Belize 42718
Suriname 40720
Bahrain 39000
Puerto Rico 38018
United Kingdom 35633
Guinea-Bissau 33000
Norway 29504
Libya 28200
Albania 27583
Luxembourg 27000
Israel 24964
Latvia 23567
Sudan 23144
Solomon Islands 22084
Eritrea 21184
Sao Tome & Principe 20700
New Caledonia 18730
Fiji 18355
Guam 18000
Oman 18000
Japan 17917
Andorra 17600
Gambia 17550
French Polynesia 16495
Malta 14247
Martinique 12800
Samoa 12164
Guadeloupe 12000
Aruba 11900
Seychelles 7183
Saint Lucia 6851
Botswana 5569
Iceland 5318
Laos 5306
Kiribati 5106
Armenia 5000
Macedonia 4558
Turkey 4277
San Marino 4030
Brunei 3473
Vanuatu 3400
Denmark 3365
Finland 3006
Swaziland 2896
Cayman Islands 2689
Estonia 2245
Kosovo 2100
American Samoa 2000
Yemen 2000
Bahamas 1963
Gibraltar 1640
Algeria 1592
Nepal 1536
Niger 1389
Cook Islands 1349
Liechtenstein 1327
Barbados 1000
Antigua & Barbuda 891
Croatia 691
Palestine 650
Mauritania 500
Uzbekistan 500
Micronesia 453
Nauru 380
Azerbaijan 378
Comoros 351
Western Sahara 316
Marshall Islands 299
Mongolia 256
Bhutan 200
Channel Islands 200
Kyrgyzstan 200
Djibouti 193
Isle of Man 150
Anguilla 90
Tajikistan 81
Falkland Islands 80
Mayotte 45
Turkmenistan 45
Grenada 43
British Virgin Islands 20
Faeroe Islands 20
Saint Helena 13
Greenland 10
Tuvalu 7
Georgia 0
Moldova 0
Montserrat 0
North Korea 0
Saint Kitts & Nevis 0
Turks & Caicos Is 0
United States Virgin Is 0
Niue -10
Tokelau Islands -10
Bermuda -25
Maldives -30
Somalia -30
Palau -50
Saint Pierre & Miquelon -261
Holy See -322
Monaco -326
Cyprus -700
Afghanistan -840
Macau -961
Wallis & Futuna Islands -1109
Saint Vincent -2000
Tunisia -2000
Tonga -2112
Trinidad & Tobago -3302
Montenegro -3515
Morocco -3981
Bulgaria -7000
Bosnia-Herzegovina -8068
Dominica -8626
Northern Mariana Is -10000
Netherlands Antilles -10249
Russia -11140
United Kingdom -11817
Jordan -12220
Iran -14425
Hong Kong -18388
Slovenia -19495
Kazakhstan -21985
Taiwan -22971
Iraq -24800
Uruguay -25191
Serbia -26308
Guyana -27412
Belarus -30380
Egypt -42976
Jamaica -45352
Lithuania -50830
Belgium -62235
Pakistan -173753
Romania -235952
Hungary -280908
Austria -321211
Czech Republic -422318
Netherlands -632164
Poland -764764
Germany -2011649
<!DOCTYPE html>
<meta charset="utf-8">
<title>The growth in catholics by country</title>
<style>
.bar.positive {
fill: #158EFF;
}
.bar.negative {
fill: #804C80;
}
.big-label {
font: 20px sans-serif;
}
.big-number {
font: 30px sans-serif;
}
.list {
font:15px sans-serif;
}
.explain {
font:15px sans-serif;
font-style: italic;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript">
var margin = {top: 30, right: 10, bottom: 10, left: 10},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var popGrowth = 794;
var x = d3.scale.linear()
.range([0, width]);
var y = d3.scale.ordinal()
.rangeBands([0, height], .2);
var commas = d3.format(",");
d3.csv("data.csv", function(csv) {
data = csv;
data.forEach(function(d) {
d.diff = parseInt(d.diff)
});
x.domain([1.5*d3.min(data, function(d) {return d.diff;}), d3.max(data, function(d) {return d.diff;})])
.nice();
y.domain(d3.range(data.length));
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.selectAll(".bar")
.data(data)
.enter().append("rect")
.attr("class", function(d) { return d.diff < 0 ? "bar negative" : "bar positive"; })
.attr("x", function(d) { return x(Math.min(0, d.diff)); })
.attr("y", function(d, i) { return y(i); })
.attr("width", function(d) { return Math.abs(x(d.diff) - x(0)); })
.attr("height", y.rangeBand());
svg.append("text")
.text("Each bar represents a single country")
.attr("class","explain")
.attr("x", 500)
.attr("y", 50)
var yLabel = 100;
svg.append("text")
.text("Worldwide growth in catholics, 2000-2010")
.attr("class","big-label")
.attr("x", 500)
.attr("y", yLabel);
svg.append("text")
.attr("class","big-number")
.attr("x", 500)
.attr("y", yLabel + 30)
.text( function(){
sum = 0
data.forEach(function(d,i){
sum += d.diff;
})
return Math.round(sum/1000000) + "m"
});
svg.append("text")
.text("Growth in total population")
.attr("class","big-label")
.attr("x", 500)
.attr("y", yLabel+75);
svg.append("text")
.attr("class","big-number")
.attr("x", 500)
.attr("y", yLabel + 75 + 30)
.text(popGrowth + "m");
// List the top ten and bottom ten countries by overall growth of catholics
svg.selectAll(".list")
.data(data.slice(0,10).concat(data.slice(225,235)))
.enter().append("text")
.text(function(d,i) {
var indexAdd
if (i > 9) {
indexAdd = 216;
}
else {
indexAdd = 1;
}
return (i+indexAdd) + ". " + d.country + " (" + commas(d.diff) + ")";
})
.attr("y", function(d,i){
var yAdd
if (i > 9) {
yAdd = 50;
}
else {
yAdd = 15;
}
return yAdd + 20*i;
})
.attr("x", 0)
.attr("class","list");
svg.append("text")
.text("...")
.attr("class","list")
.attr("x",0)
.attr("y",220)
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment