Sourced from the 2012 DC Bicycle Count Summary, visualized with d3js.
Created
December 10, 2012 22:58
-
-
Save tmcw/4254116 to your computer and use it in GitHub Desktop.
Gender Breakdown of DC Cyclists 2005-2012
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
year | Male | Female | |
---|---|---|---|
2005 | 76.9 | 23.1 | |
2006 | 76.9 | 23.1 | |
2007 | 73.7 | 26.5 | |
2008 | 82.1 | 17.3 | |
2009 | 81.0 | 19.0 | |
2010 | 77.0 | 23.0 | |
2011 | 75.6 | 24.4 | |
2012 | 77.3 | 22.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
body { | |
font: 10px sans-serif; | |
} | |
.axis path, | |
.axis line { | |
fill: none; | |
stroke: #000; | |
shape-rendering: crispEdges; | |
} | |
.browser text { | |
text-anchor: end; | |
fill:#fff; | |
font-size:30px; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.js"></script> | |
<script> | |
var margin = {top: 20, right: 20, bottom: 30, left: 50}, | |
width = 960 - margin.left - margin.right, | |
height = 500 - margin.top - margin.bottom; | |
var parseDate = d3.time.format("%Y").parse, | |
formatPercent = d3.format(".0%"); | |
var x = d3.time.scale() | |
.range([0, width]); | |
var y = d3.scale.linear() | |
.range([height, 0]); | |
var color = d3.scale.category20(); | |
var xAxis = d3.svg.axis() | |
.scale(x) | |
.orient("bottom"); | |
var yAxis = d3.svg.axis() | |
.scale(y) | |
.orient("left") | |
.tickFormat(formatPercent); | |
var area = d3.svg.area() | |
.x(function(d) { return x(d.date); }) | |
.y0(function(d) { return y(d.y0); }) | |
.y1(function(d) { return y(d.y0 + d.y); }); | |
var stack = d3.layout.stack() | |
.values(function(d) { return d.values; }); | |
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 + ")"); | |
d3.csv("bikes.csv", function(error, data) { | |
color.domain(['Male', 'Female']); | |
data.forEach(function(d) { | |
d.date = parseDate(d.year); | |
}); | |
var bikers = stack(color.domain().map(function(name) { | |
return { | |
name: name, | |
values: data.map(function(d) { | |
return {date: d.date, y: d[name] / 100}; | |
}) | |
}; | |
})); | |
x.domain(d3.extent(data, function(d) { return d.date; })); | |
var l = svg.selectAll(".browser") | |
.data(bikers) | |
.enter().append("g") | |
.attr("class", "browser"); | |
l.append("path") | |
.attr("class", "area") | |
.attr("d", function(d) { return area(d.values); }) | |
.style("fill", function(d) { return color(d.name); }); | |
l.append("text") | |
.datum(function(d) { return {name: d.name, value: d.values[d.values.length - 1]}; }) | |
.attr("transform", function(d) { return "translate(" + x(d.value.date) + "," + y(d.value.y0 + d.value.y / 2) + ")"; }) | |
.attr("x", -6) | |
.attr("dy", ".35em") | |
.text(function(d) { return d.name; }); | |
svg.append("g") | |
.attr("class", "x axis") | |
.attr("transform", "translate(0," + height + ")") | |
.call(xAxis); | |
svg.append("g") | |
.attr("class", "y axis") | |
.call(yAxis); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment