Skip to content

Instantly share code, notes, and snippets.

@gigiaa
Created April 24, 2015 14:52
Show Gist options
  • Save gigiaa/1953f23f392924d7d525 to your computer and use it in GitHub Desktop.
Save gigiaa/1953f23f392924d7d525 to your computer and use it in GitHub Desktop.
Scatterplot of the gender balance in parliaments and of the expected years of school attended by girls.
Country femaleYear womenSeats
Norway 18.2 0.657
Australia 20.3 0.412
Switzerland 15.6 0.374
Netherlands 18.0 0.607
United States 17.4 0.222
Germany 16.2 0.479
New Zealand 20.2 0.476
Canada 16.2 0.389
Singapore 15.5 0.320
Denmark 17.6 0.642
Ireland 18.5 0.242
Sweden 16.6 0.808
Iceland 19.9 0.658
United Kingdom 16.7 0.291
Korea (Republic of) 16.1 0.186
Japan 15.1 0.121
Liechtenstein 13.8 0.250
Israel 16.1 0.290
France 16.3 0.335
Luxembourg 14.0 0.277
Belgium 16.5 0.637
Austria 15.9 0.402
Finland 17.6 0.739
Slovenia 17.9 0.327
Italy 16.8 0.441
Spain 17.5 0.544
Czech Republic 16.9 0.260
Greece 16.6 0.266
Qatar 14.0 0.001
Cyprus 14.0 0.120
Estonia 17.5 0.263
Saudi Arabia 15.9 0.248
Poland 16.3 0.279
Lithuania 17.3 0.318
Slovakia 15.6 0.230
Malta 14.7 0.167
United Arab Emirates 13.9 0.212
Portugal 16.5 0.402
Chile 15.3 0.162
Hungary 15.7 0.097
Cuba 15.1 0.955
Bahrain 15.1 0.231
Kuwait 15.2 0.066
Croatia 15.2 0.313
Latvia 16.3 0.299
Argentina 17.5 0.605
Uruguay 16.6 0.140
Montenegro 15.5 0.209
Belarus 16.3 0.419
Romania 14.5 0.131
Libya 16.4 0.198
Oman 13.9 0.106
Russian Federation 14.5 0.137
Bulgaria 14.5 0.326
Barbados 17.2 0.275
Palau 14.6 0.115
Antigua and Barbuda 13.7 0.241
Malaysia 12.7 0.162
Mauritius 15.9 0.232
Trinidad and Tobago 12.5 0.352
Panama 12.9 0.092
Lebanon 13.0 0.032
Venezuela 15.3 0.204
Costa Rica 13.9 0.629
Turkey 13.8 0.165
Kazakhstan 15.4 0.222
Seychelles 12.1 0.778
Mexico 12.9 0.562
Sri Lanka 13.9 0.061
Saint Kitts and Nevis 13.4 0.071
Iran 15.0 0.032
Azerbaijan 11.6 0.190
Serbia 14.1 0.497
Jordan 13.5 0.137
Grenada 16.3 0.333
Georgia 12.8 0.136
Peru 13.2 0.275
Ukraine 15.3 0.104
Macedonia 13.4 0.519
Belize 14.1 0.154
Armenia 13.6 0.120
Thailand 13.4 0.186
Tunisia 15.0 0.365
SVincent and Grenadines 13.4 0.150
China 13.0 0.306
Algeria 14.2 0.348
Albania 10.3 0.217
Jamaica 12.4 0.183
Saint Lucia 12.5 0.208
Colombia 13.5 0.157
Tonga 14.0 0.037
Suriname 12.9 0.133
Mongolia 15.6 0.175
Maldives 12.8 0.069
Samoa 13.3 0.043
Indonesia 12.8 0.228
Botswana 11.7 0.086
Egypt 12.7 0.029
Paraguay 12.2 0.225
Bolivia 12.9 0.431
Moldova 12.1 0.247
El Salvador 12.0 0.355
Uzbekistan 11.3 0.238
Philippines 11.5 0.368
Syria 12.0 0.136
Iraq 8.7 0.337
Guyana 11.7 0.457
Cape Verde 13.6 0.263
Kyrgyzstan 12.7 0.304
Guatemala 10.3 0.153
Namibia 11.4 0.333
Timor-Leste 11.3 0.625
Morocco 10.6 0.123
Honduras 12.1 0.243
Vanuatu 10.2 0.001
Nicaragua 10.8 0.673
Tajikistan 10.4 0.213
Kiribati 12.7 0.095
India 11.3 0.122
Cambodia 10.3 0.221
Bhutan 12.5 0.075
Ghana 10.9 0.122
Lao PDR 9.5 0.333
Congo 10.9 0.106
Zambia 13.0 0.129
Sao Tome and Principe 11.4 0.222
Bangladesh 10.3 0.246
Equatorial Guinea 6.9 0.232
Nepal 12.5 0.496
Pakistan 6.9 0.245
Kenya 10.7 0.248
Swaziland 10.9 0.280
Angola 8.7 0.517
Rwanda 10.3 1.078
Nigeria 8.2 0.071
Cameroon 9.5 0.191
Yemen 7.7 0.007
Madagascar 10.2 0.188
Zimbabwe 9.1 0.542
Solomon Islands 8.8 0.020
Tanzania 9.0 0.563
Comoros 12.3 0.031
Mauritania 8.1 0.238
Lesotho 11.6 0.366
Senegal 7.8 0.744
Uganda 10.6 0.538
Benin 9.4 0.092
Togo 8.5 0.182
Afghanistan 7.2 0.382
Djibouti 5.9 0.146
Ethiopia 8.0 0.343
Malawi 10.8 0.287
Liberia 8.9 0.132
Mali 7.6 0.114
Mozambique 8.9 0.645
Burundi 9.6 0.537
Burkina Faso 7.0 0.187
Eritrea 3.7 0.282
Sierra Leone 6.1 0.142
Chad 5.9 0.175
Central African Republic 5.9 0.143
Congo DR 8.4 0.091
Niger 4.8 0.153
<!DOCTYPE html>
<html lang="en">
<head>
<title>Gender scatterplot</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<style type="text/css">
body {
background-color: ivory;
font-family: sans-serif;
}
h1 {
font-size: 20px;
margin: 0;
font-family: verdana;
}
p {
font-size: 13px;
margin: 10px 0 0 0;
font-family: verdana;
}
svg {
background-color: ivory;
}
circle:hover {
fill: cadetblue;
}
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 11px;
}
</style>
</head>
<body>
<h1>Gender balance in parliaments and expectancy of years of school by girls in 2013</h1>
<p>Gender balance: Score of women seats in parliaments vs. expected years of school attended by girls. Source: <a href="http://http://hdr.undp.org/en">UNDP human development index</a>, 2014</p>
<script type="text/javascript">
var w = 1000;
var h = 800;
var padding = [ 20, 10, 50, 110 ]; //Top, right, bottom, left
var xScale = d3.scale.linear()
.range([ padding[3], w - padding[1] - padding[3] ]);
var yScale = d3.scale.linear()
.range([ padding[0], h - padding[2] ]);
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom")
.ticks(18);
var yAxis = d3.svg.axis()
.scale(yScale)
.orient("left")
.tickFormat(function(d) {
return d ;
});
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
d3.csv("completedatabase.csv", function(data) {
xScale.domain([
d3.min(data, function(d) {
return +d.femaleYear;
}),
d3.max(data, function(d) {
return +d.femaleYear;
})
]);
yScale.domain([
d3.max(data, function(d) {
return +d.womenSeats;
}),
d3.min(data, function(d) {
return +d.womenSeats;
})
]);
var circles = svg.selectAll("circle")
.data(data)
.enter()
.append("circle");
circles.attr("cx", function(d) {
return xScale(d.femaleYear);
})
.attr("cy", function(d) {
return yScale(d.womenSeats);
})
.attr("r", 1)
.attr("fill", "mediumvioletred")
.append("title")
.text(function(d) {
return d.Country + "'s expected school years for girls is " + d.femaleYear + ", and " + d.womenSeats + " is the score of women seats in the parliament";
});
circles.sort(function(a, b) {
return d3.ascending(+a.femaleYear, +b.femaleYear);
})
.transition()
.delay(function(d, i) {
return i * 50;
})
.duration(1000)
.attr("r", 9);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + (h - padding[2] + 10) + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + (padding[3] - 8) + ",0)")
.call(yAxis);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment