Skip to content

Instantly share code, notes, and snippets.

@mgold
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgold/37c699e424ff40705e82 to your computer and use it in GitHub Desktop.
Save mgold/37c699e424ff40705e82 to your computer and use it in GitHub Desktop.
Forested Land Area by Country

Each bar shows the percent of a country's land area covered by forests. Data is taken from No Ceilings series LACFORES.

This is assignment 3 for the Knight D3 course.

<!DOCTYPE html>
<html>
<head>
<title>Knight D3 Module 3</title>
</head>
<body>
<svg width=960 height=500>
</svg>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script>
d3.csv("no-ceilings-data.csv", function(row){
//accessor to convert to numbers
var obj = {}
Object.keys(row).forEach(function(k){
var v = row[k]
obj[k] = +v || v;
})
return obj
}, function(err, data){
if (err) return console.error(err);
var marginTop = 20, marginLeft = 150;
var barHeight = 15, barMargin = 2;
data = data.filter(function(d){return d.population > 5});
data.sort(function(a,b){return d3.descending(a.forests, b.forests)})
var svg = d3.select("svg");
var rects = svg.selectAll("rect")
.data(data)
.enter()
.append("g")
.attr("transform", function(d,i){return "translate(0,"+(i*(barHeight+barMargin)+marginTop)+")"});
rects.append("text").text(function(d){return d.country})
.style("text-anchor", "end")
.style("font-family", "sans-serif")
.style("font-size", "12px")
.attr("x", marginLeft)
rects.append("text").text(function(d){return d.forests+'%'})
.style("font-family", "sans-serif")
.style("font-size", "12px")
.attr("x", marginLeft+5)
rects.append("rect")
.attr("x", marginLeft+40)
.attr("y", -barHeight + 3)
.attr("height", barHeight)
.attr("width", function(d){return 4*d.forests})
.style("fill", "green")
})
</script>
</body>
</html>
country population gdp under-five mortality teen pregnancy high school enrollment internet access forests
Algeria 37.5 438 2.0 1.0 97.6 15.2 0.6
Angola 20.82 136.3 16.35 17.02 31.5 16.9 46.9
Antigua & Barbuda 0.09 1.1 0.99 4.93 105.4 59 22.2
Argentina 41.28 737.1 1.42 5.44 91.9 55.8 10.7
Australia 22.92 842.5 0.49 1.21 135.5 82.3 19.4
Austria 8.48 306.3 0.4 0.41 97.7 81 47.1
Azerbaijan 9.24 107.3 3.52 4.0 100.3 54.2 11.3
Bahamas 0.37 5.9 1.69 2.85 92.9 71.7 51.4
Bahrain 1.25 33.5 0.96 1.38 95.5 88 1.4
Bangladesh 154.7 326.1 4.09 8.06 53.6 6.3 11.1
Barbados 0.28 15.6 1.84 4.84 104.7 73.3 18.6
Belarus 9.42 142.6 0.52 2.06 106.4 46.9 41.6
Belgium 10.65 363.6 0.42 0.67 107.3 82 22.4
Belize 0.32 2.5 1.83 7.14 84 25 61.1
Benin 10.05 15.1 8.95 9.02 47.7 3.8 41.2
Bhutan 0.74 4.5 4.46 4.09 73.9 25.4 69.1
Bolivia 10.5 52.8 4.14 7.19 77.3 34.2 52.7
Brunei Darussalam 0.41 26.1 0.8 2.3 107.8 60.3 72.1
Bulgaria 7.28 84.5 1.21 3.59 93.1 55.1 36.1
Burkina Faso 16.46 22.4 10.24 11.54 25.9 3.7 20.6
Burundi 9.85 6.5 10.43 3.03 28.5 1.2 6.7
Cameroon 21.7 49.4 9.49 11.58 50.4 5.7 42.1
Canada 34.88 1291 0.53 1.45 103.4 86.8 34.1
Cape Verde 0.49 1.7 2.22 7.06 92.7 34.7 21.1
CAR 4.58 4.3 12.86 9.83 17.8 3 36.3
Chad 12.45 22.2 14.98 15.2 22.8 2.1 9.2
Chile 17.4 276.7 0.91 5.53 89 61.4 21.7
China 1345 13113 1.4 0.86 89 42.3 21.9
Colombia 48.32 435.8 1.76 6.85 92.8 49 54.5
Comoros 0.72 1 7.76 5.11 73.5 6 1.6
Congo 4.34 16.3 9.6 12.67 53.7 6.1 65.6
Costa Rica 4.82 56.4 0.99 6.08 103.6 47.5 51
Croatia 4.27 67.9 0.47 1.27 98.4 63 34.3
Cuba 11.18 109.1 0.55 4.31 90.2 25.6 26.1
Cyprus 0.86 20.5 0.32 0.55 95.3 61 18.7
Czech Republic 10.54 250.4 0.38 0.49 96.6 75 34.4
DR Congo 65.71 23.7 14.57 13.53 43.3 1.7 68
Denmark 5.6 180.6 0.37 0.51 124.7 93 12.8
Djibouti 0.86 2.2 8.09 1.86 43.8 8.3 0.3
Dominican Republic 9.7 100.9 2.71 9.96 75.9 45 40.8
Ecuador 14.9 138.9 2.33 7.7 86.8 35.1 35.6
Egypt 80.72 771.2 2.1 4.3 86.3 44.1 0.1
El Salvador 6.25 41.5 1.59 7.6 69.2 25.5 13.9
Eritrea 6.13 5.6 5.18 6.53 29.8 0.8 15.2
Estonia 1.29 25.5 0.36 1.68 107.1 79 52.3
Fiji 0.87 5.9 2.24 4.28 88.3 33.7 55.5
Finland 5.41 177.1 0.29 0.92 107.7 91 72.9
France 63.94 2042 0.41 0.57 109.7 83 29
Gambia 1.79 2.5 7.29 11.58 57.5 12.4 48
Germany 80.52 2853 0.41 0.38 101.3 84 31.8
Ghana 25.37 72.3 7.2 5.84 58.2 17.1 21.7
Greece 11.13 234.5 0.48 1.19 107.9 56 30.3
Grenada 0.11 0.9 1.35 3.54 107.8 42.1 50
Guatemala 15.08 110.9 3.2 9.72 65.1 16 33.7
Guinea 11.45 10.6 10.12 13.1 38.1 1.5 26.6
Guyana 0.8 4.2 3.52 8.85 101 33 77.2
Honduras 7.94 29.1 2.29 8.4 73.1 18.1 46.4
Hungary 9.96 169 0.62 1.21 101.6 72 22.6
Iceland 0.32 10.8 0.23 1.15 108.6 96.2 0.3
India 1220 5557 5.63 3.28 68.5 12.6 23
Indonesia 248.22 1949.1 3.1 4.83 82.5 15.4 52.1
Iran 76.42 918.9 1.76 3.16 86.3 26 6.8
Ireland 4.58 172.4 0.4 0.82 119.1 79 10.7
Israel 7.9 224.8 0.42 0.78 101.7 73.4 7.1
Italy 60.88 1605 0.38 0.4 100.7 58 31.1
Jamaica 2.71 11.6 1.68 7.01 88.6 46.5 31.1
Japan 127.25 3994 0.3 0.54 101.8 79.1 68.5
Jordan 7.01 63.6 1.91 2.65 87.8 41 1.1
Kazakhstan 16.91 201 1.87 2.99 97.7 53.3 1.2
Kyrgyzstan 5.47 11.6 2.66 2.93 88.2 21.7 5
Laos 6.65 26 7.18 6.5 46.5 10.7 68.2
Latvia 2.06 32.5 0.87 1.35 97.7 74 53.8
Lebanon 4.58 64.1 0.93 1.2 74 61.2 13.4
Lesotho 2.05 4.3 9.96 8.94 53.3 4.6 1.4
Liberia 4.19 2.9 7.48 11.74 45.2 3.8 44.9
Lithuania 3 56.3 0.54 1.06 105.9 68 34.5
Luxembourg 0.52 33.3 0.22 0.83 101 92 33.6
Macedonia 2.06 19.6 0.74 1.83 82.8 63.1 39.2
Madagascar 21.93 18.8 5.82 12.28 38 2.1 21.6
Malawi 15.91 13.9 7.1 14.48 34.2 4.4 34.4
Malaysia 29.24 569.6 0.85 0.57 67.2 65.8 62.3
Mali 16.32 21.2 12.8 17.56 44.5 2.2 10.2
Malta 0.42 10 0.68 1.82 86.3 70 0
Mauritania 3.8 7 8.4 7.33 26.8 5.4 0.2
Mauritius 1.29 16.9 1.51 3.09 95.9 41.4 17.2
Mexico 114.98 1572 1.62 6.34 85.7 38.4 33.3
Mongolia 2.8 20.7 2.75 1.87 103.5 16.4 7
Morocco 32.52 199.9 3.11 3.58 68.9 55 11.5
Mozambique 25.2 22.2 8.97 13.78 25.9 4.8 49.6
Burma 61.18 65.8 5.23 1.21 50.2 1.1 48.3
Nepal 27.47 36.9 4.16 7.37 65.8 11.1 25.4
Netherlands 16.73 651.7 0.41 0.62 129.9 93 10.8
New Zealand 4.48 116.3 0.57 2.53 119.5 89.5 30.9
Nicaragua 6.92 19.1 2.44 10.08 68.9 13.5 25.7
Niger 17.16 11.2 11.35 20.48 15.9 1.4 1
Nigeria 170.1 609.5 12.37 11.96 43.8 32.9 9.9
Norway 5.01 238.3 0.28 0.78 111.1 95 33.1
Oman 3.62 129.9 1.16 1.06 93.5 60 0
Pakistan 179.22 746.8 8.59 2.73 36.6 10 2.2
Panama 3.79 63.9 1.85 7.85 84 45.2 43.7
Papua New Guinea 7.17 25.2 6.3 6.21 40.2 2.3 63.4
Paraguay 6.69 35.4 2.2 6.7 69.6 27.1 44.3
Peru 30.77 277.6 1.82 5.07 89.8 38.2 53.1
Poland 38.51 705.3 0.5 1.22 97.7 65 30.5
Portugal 10.54 221.4 0.36 1.26 112.9 64 38.1
Qatar 1.84 162.2 0.74 0.95 111.6 88.1 0
South Korea 50 1513 0.38 0.22 97.2 84.1 63
Moldova 3.56 10.6 1.76 2.93 88.2 43.4 11.7
Romania 21.43 240.2 1.22 3.1 95 50 28.6
Russia 142.8 2164 1.03 2.57 95.3 53.3 49.4
Rwanda 11.46 14.1 5.5 3.36 31.8 8 17.6
St. Lucia 0.18 1.2 1.75 5.63 91.1 48.6 77
St. Vincent & the Grenadines 0.11 0.9 2.34 5.45 100.9 47.5 69.2
Samoa 0.19 1.2 1.78 2.83 85.7 12.9 60.4
Sao Tome & Principe 0.19 0.5 5.32 6.51 71.5 21.6 28.1
Saudi Arabia 28.9 1285.5 0.86 1.02 114.3 54 0.5
Senegal 13.73 26.6 5.96 9.44 41 19.2 44
Serbia 7.23 70.8 0.66 1.69 91.7 48.1 31
Seychelles 0.09 1.8 1.31 5.63 101.3 47.1 89.1
Slovakia 5.43 114.8 0.75 1.59 93.9 80 40.2
Slovenia 2.06 50.5 0.31 0.06 97.6 70 62.2
Solomon Islands 0.55 1 3.11 6.49 48.4 7 79.1
South Africa 52.39 560.6 4.46 5.09 101.9 41 7.6
Spain 46.76 1220 0.45 1.06 130.8 72 36.4
Sri Lanka 21.1 160.5 0.96 1.69 99.3 18.3 28.8
Suriname 0.53 4.6 2.08 3.52 85.4 34.7 94.6
Swaziland 1.23 7 7.97 7.2 59.9 20.8 32.7
Sweden 9.56 334.1 0.29 0.65 98.4 94 68.7
Switzerland 7.99 314.2 0.43 0.19 96.3 85.2 31
Syria 21.41 76 1.51 4.16 74.4 24.3 2.7
Tajikistan 7.94 16.6 5.83 4.28 87 14.5 2.9
Tanzania 47.78 68.5 5.4 12.27 35 4 37.7
Thailand 66.79 565.2 1.32 4.1 87 26.5 37.1
Togo 6.64 7.6 9.55 9.15 54.9 4 5.3
Tonga 0.1 0.5 1.28 1.81 104.3 34.9 12.5
Tunisia 10.87 101.4 1.61 0.46 91.1 41.4 6.5
Turkey 74.7 1015.7 1.42 3.09 86.1 45.1 14.7
Ukraine 45.45 340.4 1.07 2.57 97.8 33.7 16.8
United Kingdom 63.14 2069 0.48 2.58 95.4 87 11.9
USA 313.95 14138 0.71 3.1 93.7 81 33.2
Uruguay 3.38 54.2 0.72 5.83 90.3 55.1 10
Uzbekistan 29.78 124.9 3.96 3.88 105.2 36.5 7.7
Vanuatu 0.25 0.9 1.79 4.48 59.5 10.6 36.1
Venezuela 29.51 348.6 1.53 8.32 85.4 44 52.5
Yemen 23.85 96.1 6.0 4.7 46.9 17.4 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment