Skip to content

Instantly share code, notes, and snippets.

@timsny
Created April 17, 2015 15:21
Show Gist options
  • Save timsny/58854c21325d46108a77 to your computer and use it in GitHub Desktop.
Save timsny/58854c21325d46108a77 to your computer and use it in GitHub Desktop.
Mod4 #2
Location Y2003 Y2004 Y2005 Y2006 Y2007 Y2008 Y2009 Y2010 Y2011 Y2012 Y2013
Australia 40.622 40.992 41.269 41.624 41.903 42.176 42.998 42.847 43.699 45.195 45.772
Austria 40.093 40.853 41.77 42.862 43.87 43.905 43.827 44.446 44.914 45.364 45.696
Belgium 50.007 51.396 51.875 52.341 52.884 52.657 51.982 52.73 52.462 52.322 52.497
Canada 39.399 39.526 40.482 40.921 40.913 40.889 41.24 41.857 42.276 42.276 42.739
Chile 14.243 14.884 15.743 16.295 16.965 17.299 17.407 17.896 18.326 19.19 19.859
Czech Republic 23.318 24.368 25.443 27.1 28.244 28.306 27.599 28.197 28.731 28.855 28.754
Denmark 43.4 44.82 45.508 46.077 46.158 45.487 44.607 46.739 46.685 46.912 46.879
Estonia 16.183 17.229 18.241 19.274 20.784 20.024 20.42 21.514 21.359 22.381 22.705
Finland 39.128 40.387 41.119 42.123 43.419 42.957 40.957 42.294 42.971 42.286 42.597
France 47.318 47.647 48.264 49.646 49.571 49.21 48.9 49.668 50.273 50.622 50.862
Germany 46.578 47.047 47.76 48.684 49.427 49.505 48.226 49.424 50.403 50.723 50.914
Greece 28.014 28.832 28.097 29.35 30.188 29.741 28.939 28.98 26.89 28.224 28.346
Hungary 19.01 20.032 20.938 21.712 21.724 22.323 21.552 21.73 21.933 22.556 22.824
Iceland 32.714 35.273 36.385 36.308 38.63 38.692 40.937 40.225 40.081 40.676 40.786
Ireland 44.389 45.174 45.31 45.784 46.373 45.967 47.528 49.689 51.991 52.007 50.63
Israel 28.22 29.508 29.931 30.933 31.309 31.368 31.317 32.212 32.711 32.846 33.213
Italy 38.136 38.516 38.735 38.738 38.706 38.453 37.616 38.472 38.665 38.359 38.379
Japan 32.256 33.05 33.464 33.695 34.268 34.342 34.045 35.389 35.4 35.553 36.066
Korea 19.953 20.796 21.694 22.578 23.931 25.118 25.526 27.372 29.19 28.34 29.885
Luxembourg 61.926 63.519 65.357 65.952 66.66 63.918 64.183 68.414 70.708 68.309 68.994
Mexico 14.779 15.024 14.929 15.485 15.84 15.353 15.438 14.681 15.119 15.218 15.103
Netherlands 48.449 49.21 50.467 51.4 52.046 52.264 51.264 52.19 52.562 51.86 52.3
New Zealand 27.542 27.444 27.748 27.917 28.678 28.156 29.463 29.171 29.532 30.436 30.165
Norway 63.819 65.119 65.846 65.253 64.052 61.901 62.135 62.381 62.067 62.607 62.633
Poland 17.069 17.741 18.03 18.543 19.051 19.147 19.728 21.069 22.004 22.423 22.854
Portugal 23.485 24.002 24.271 24.706 25.092 25.224 25.155 25.967 26.32 26.449 26.702
Russia 11.24 11.896 12.514 13.339 14.119 14.792 14.128 14.64 15.041 15.385 15.591
Slovak Republic 22.706 23.341 24.091 25.478 27.363 27.919 27.167 28.519 28.974 29.489 30.44
Slovenia 29.251 30.238 32.331 34.226 35.681 35.583 33.342 34.261 35.562 35.371 35.247
Spain 35.415 35.503 35.635 35.843 36.27 36.414 37.307 38.178 38.786 39.738 40.415
Sweden 41.838 43.299 44.414 45.891 46.028 45.212 44.141 45.605 45.913 45.844 46.295
Switzerland 40.232 40.522 41.572 42.589 43.505 43.701 42.795 43.562 43.481 43.721 44.487
Turkey 18.009 19.577 20.58 21.536 22.6 22.49 21.562 22.254 22.964 22.849 23.411
United Kingdom 42.023 42.964 43.221 44.245 44.951 45.01 43.919 44.575 45.099 44.512 44.487
United States 49.586 50.87 51.87 52.287 52.802 53.207 54.747 56.276 56.394 56.653 56.882
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Cleaning Up</title>
<script type="text/javascript" src="http://d3.js.org/d3.v3.js"></script>
<style type="text/css">
body {
background-color: aliceblue;
font-family: Georgia, Arial, sans-serif;
}
h1 {
font-size: 24px;
margin: 0;
}
p {
font-size: 14px;
margin: 10px 0 0 0;
}
svg {
background-color: aliceblue;
}
rect:hover {
fill: orange;
}
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 11px;
}
.y.axis path,
.y.axis line {
opacity: 0;
}
.x.axis path,
.x axis line {
opacity: 0;
}
</style>
</head>
<body>
<h1>GDP Per Hour</h1>
<p>GDP Per Hour by country.
<script type="text/javascript">
var w = 700;
var h = 600;
var padding = [ 20, 10, 30, 120 ]; //Top, right, bottom, left
var widthScale = d3.scale.linear()
.range([ 0, w - padding[1] - padding[3] ]);
var heightScale = d3.scale.ordinal()
.rangeRoundBands([ padding[0], h - padding[2] ], 0.1);
var xAxis = d3.svg.axis()
.scale(widthScale)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(heightScale)
.orient("left");
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
d3.csv("GDP_per_Hour.csv", function(data) {
data.sort(function(a, b) {
return d3.descending(+a.Y2013, +b.Y2013);
});
widthScale.domain([ 0, d3.max(data, function(d) {
return +d.Y2013;
}) ]);
heightScale.domain(data.map(function(d) { return d.Location; } ));
var rects = svg.selectAll("rect")
.data(data)
.enter()
.append("rect");
rects.attr("x", padding[3])
.attr("y", function(d) {
return heightScale(d.Location);
})
.attr("width", function(d) {
return widthScale(d.Y2013);
})
.attr("height", heightScale.rangeBand())
.attr("fill", "olivedrab")
.append("title")
.text(function(d) {
return d.location + "'s 2013 GDP per hour was " + d.Y2013;
});
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(" + padding[3] + "," + (h - padding[2]) + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + padding[3] + ",0)")
.call(yAxis);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment