Skip to content

Instantly share code, notes, and snippets.

@octaviomtz
Created April 19, 2015 16:04
Show Gist options
  • Save octaviomtz/2567e689d4c27d89f4c5 to your computer and use it in GitHub Desktop.
Save octaviomtz/2567e689d4c27d89f4c5 to your computer and use it in GitHub Desktop.
alcohol consumption
country beer_servings spirit_servings wine_servings total_litres_of_pure_alcohol
Afghanistan 0 0 0 0
Albania 89 132 54 4.9
Algeria 25 0 14 0.7
Andorra 245 138 312 12.4
Angola 217 57 45 5.9
Antigua & Barbuda 102 128 45 4.9
Argentina 193 25 221 8.3
Armenia 21 179 11 3.8
Australia 261 72 212 10.4
Austria 279 75 191 9.7
Azerbaijan 21 46 5 1.3
Bahamas 122 176 51 6.3
Bahrain 42 63 7 2
Bangladesh 0 0 0 0
Barbados 143 173 36 6.3
Belarus 142 373 42 14.4
Belgium 295 84 212 10.5
Belize 263 114 8 6.8
Benin 34 4 13 1.1
Bhutan 23 0 0 0.4
Bolivia 167 41 8 3.8
Bosnia-Herzegovina 76 173 8 4.6
Botswana 173 35 35 5.4
Brazil 245 145 16 7.2
Brunei 31 2 1 0.6
Bulgaria 231 252 94 10.3
Burkina Faso 25 7 7 4.3
Burundi 88 0 0 6.3
Cote d'Ivoire 37 1 7 4
Cabo Verde 144 56 16 4
Cambodia 57 65 1 2.2
Cameroon 147 1 4 5.8
Canada 240 122 100 8.2
Central African Republic 17 2 1 1.8
Chad 15 1 1 0.4
Chile 130 124 172 7.6
China 79 192 8 5
Colombia 159 76 3 4.2
Comoros 1 3 1 0.1
Congo 76 1 9 1.7
Cook Islands 0 254 74 5.9
Costa Rica 149 87 11 4.4
Croatia 230 87 254 10.2
Cuba 93 137 5 4.2
Cyprus 192 154 113 8.2
Czech Republic 361 170 134 11.8
North Korea 0 0 0 0
DR Congo 32 3 1 2.3
Denmark 224 81 278 10.4
Djibouti 15 44 3 1.1
Dominica 52 286 26 6.6
Dominican Republic 193 147 9 6.2
Ecuador 162 74 3 4.2
Egypt 6 4 1 0.2
El Salvador 52 69 2 2.2
Equatorial Guinea 92 0 233 5.8
Eritrea 18 0 0 0.5
Estonia 224 194 59 9.5
Ethiopia 20 3 0 0.7
Fiji 77 35 1 2
Finland 263 133 97 10
France 127 151 370 11.8
Gabon 347 98 59 8.9
Gambia 8 0 1 2.4
Georgia 52 100 149 5.4
Germany 346 117 175 11.3
Ghana 31 3 10 1.8
Greece 133 112 218 8.3
Grenada 199 438 28 11.9
Guatemala 53 69 2 2.2
Guinea 9 0 2 0.2
Guinea-Bissau 28 31 21 2.5
Guyana 93 302 1 7.1
Haiti 1 326 1 5.9
Honduras 69 98 2 3
Hungary 234 215 185 11.3
Iceland 233 61 78 6.6
India 9 114 0 2.2
Indonesia 5 1 0 0.1
Iran 0 0 0 0
Iraq 9 3 0 0.2
Ireland 313 118 165 11.4
Israel 63 69 9 2.5
Italy 85 42 237 6.5
Jamaica 82 97 9 3.4
Japan 77 202 16 7
Jordan 6 21 1 0.5
Kazakhstan 124 246 12 6.8
Kenya 58 22 2 1.8
Kiribati 21 34 1 1
Kuwait 0 0 0 0
Kyrgyzstan 31 97 6 2.4
Laos 62 0 123 6.2
Latvia 281 216 62 10.5
Lebanon 20 55 31 1.9
Lesotho 82 29 0 2.8
Liberia 19 152 2 3.1
Libya 0 0 0 0
Lithuania 343 244 56 12.9
Luxembourg 236 133 271 11.4
Madagascar 26 15 4 0.8
Malawi 8 11 1 1.5
Malaysia 13 4 0 0.3
Maldives 0 0 0 0
Mali 5 1 1 0.6
Malta 149 100 120 6.6
Marshall Islands 0 0 0 0
Mauritania 0 0 0 0
Mauritius 98 31 18 2.6
Mexico 238 68 5 5.5
Micronesia 62 50 18 2.3
Monaco 0 0 0 0
Mongolia 77 189 8 4.9
Montenegro 31 114 128 4.9
Morocco 12 6 10 0.5
Mozambique 47 18 5 1.3
Myanmar 5 1 0 0.1
Namibia 376 3 1 6.8
Nauru 49 0 8 1
Nepal 5 6 0 0.2
Netherlands 251 88 190 9.4
New Zealand 203 79 175 9.3
Nicaragua 78 118 1 3.5
Niger 3 2 1 0.1
Nigeria 42 5 2 9.1
Niue 188 200 7 7
Norway 169 71 129 6.7
Oman 22 16 1 0.7
Pakistan 0 0 0 0
Palau 306 63 23 6.9
Panama 285 104 18 7.2
Papua New Guinea 44 39 1 1.5
Paraguay 213 117 74 7.3
Peru 163 160 21 6.1
Philippines 71 186 1 4.6
Poland 343 215 56 10.9
Portugal 194 67 339 11
Qatar 1 42 7 0.9
South Korea 140 16 9 9.8
Moldova 109 226 18 6.3
Romania 297 122 167 10.4
Russian Federation 247 326 73 11.5
Rwanda 43 2 0 6.8
St. Kitts & Nevis 194 205 32 7.7
St. Lucia 171 315 71 10.1
St. Vincent & the Grenadines 120 221 11 6.3
Samoa 105 18 24 2.6
San Marino 0 0 0 0
Sao Tome & Principe 56 38 140 4.2
Saudi Arabia 0 5 0 0.1
Senegal 9 1 7 0.3
Serbia 283 131 127 9.6
Seychelles 157 25 51 4.1
Sierra Leone 25 3 2 6.7
Singapore 60 12 11 1.5
Slovakia 196 293 116 11.4
Slovenia 270 51 276 10.6
Solomon Islands 56 11 1 1.2
Somalia 0 0 0 0
South Africa 225 76 81 8.2
Spain 284 157 112 10
Sri Lanka 16 104 0 2.2
Sudan 8 13 0 1.7
Suriname 128 178 7 5.6
Swaziland 90 2 2 4.7
Sweden 152 60 186 7.2
Switzerland 185 100 280 10.2
Syria 5 35 16 1
Tajikistan 2 15 0 0.3
Thailand 99 258 1 6.4
Macedonia 106 27 86 3.9
Timor-Leste 1 1 4 0.1
Togo 36 2 19 1.3
Tonga 36 21 5 1.1
Trinidad & Tobago 197 156 7 6.4
Tunisia 51 3 20 1.3
Turkey 51 22 7 1.4
Turkmenistan 19 71 32 2.2
Tuvalu 6 41 9 1
Uganda 45 9 0 8.3
Ukraine 206 237 45 8.9
United Arab Emirates 16 135 5 2.8
United Kingdom 219 126 195 10.4
Tanzania 36 6 1 5.7
USA 249 158 84 8.7
Uruguay 115 35 220 6.6
Uzbekistan 25 101 8 2.4
Vanuatu 21 18 11 0.9
Venezuela 333 100 3 7.7
Vietnam 111 2 1 2
Yemen 6 0 0 0.1
Zambia 32 19 4 2.5
Zimbabwe 64 18 4 4.7
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Loading CSV Data with D3</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<style type="text/css">
body {
background-color: #ffffff;
}
svg {
background-color: #ffffff;
}
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 11px;
}
circle:hover {
fill: #adff2f;
}
}
</style>
</head>
<body>
<h1>About alcohol consumption</h1>
<h3>Data taken from <strong>fivethirtyeight.com</strong></h3>
<p>How much alcohol is consumed per country. Data is divided in beer consumption (x-axis), spirits consumption(y-axis) and wine consumption (size)</p>
<p>All data can found here: be http://fivethirtyeight.com/datalab/dear-mona-followup-where-do-people-drink-the-most-beer-wine-and-spirits/ </p>
<p><strong>cheers!</strong></p>
<script type="text/javascript">
var w=800;
var h=600;
var padding=[20, 10, 50, 70];
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 zSizeScale= d3.scale.linear()
.range([1, 20]);
var xAxis = d3.svg.axis()
.scale(xScale)
.ticks(5)
.tickFormat(d3.format(",.0f"))
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(yScale)
.tickFormat(d3.format(",.0f"))
.orient("left");
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
//Load in contents of CSV file
d3.csv("drinks.csv", function(data) {
data.sort(function(a,b){
return d3.descending(+a.wine_servings,+b.wine_servings);
});
xScale.domain([
d3.min(data, function(d){
return +d.beer_servings;
}), d3.max(data, function(d){
return +d.beer_servings;
}) ]);
yScale.domain([d3.max(data, function(d){
return +d.wine_servings;
}),d3.min(data, function(d){
return +d.wine_servings;
}) ]);
zSizeScale.domain([d3.min(data, function(d){
return +d.spirit_servings;
}),d3.max(data, function(d){
return +d.spirit_servings;
}) ]);
circ=svg.selectAll("circle")
.data(data)
.enter()
.append("circle")
circ.attr("cy",function(d){
return yScale(d.wine_servings);
})
.attr("r", 1)
.attr("cx",function(d){
return xScale(d.beer_servings);
})
.attr("r",3)
.attr("fill","#BF7500")
.append("title")
.text(function(d){
return "In total " +d.country + " consumes " + d.total_litres_of_pure_alcohol + " total litres of pure alcohol";
})
circ.transition()
.delay(function(d,i){
return i*100;
})
.duration(5)
.attr("r", 7)
.attr("r", function(d){
return zSizeScale(d.spirit_servings);
})
.style("stroke", "black")
.style("fill-opacity", .8)
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + (h - padding[2]) + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + (padding[3] - 5) + ",0)")
.call(yAxis);
// labels
svg.append("text") // text label for the x axis
.attr("x", w/2 )
.attr("y", h-(padding[3]/4) )
.style("text-anchor", "middle")
.style("fill", "#BF7500")
.text("Beer");
svg.append("text") // text label for the y axis
//check this for orientation
//http://www.d3noob.org/2012/12/adding-axis-labels-to-d3js-graph.html
.attr("y",30 )
.attr("x", -h/2)
.style("text-anchor", "middle")
.text("Spirits")
.style("fill", "#BF7500")
.attr("transform", "rotate(-90)");
});
d3.select("body")
.append("p")
.text("To have a fair comparison data average alcohol content is taken as well as average serving size. For more info read the reference ")
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment