Last active
August 29, 2015 14:00
-
-
Save llimllib/11408881 to your computer and use it in GitHub Desktop.
Boston Marathon 2001-2014 Chloropleth
This file contains hidden or 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
<html><head><title>Runner Chloropleth</title> | |
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
.q0-9 { fill:rgb(247,251,255); } | |
.q1-9 { fill:rgb(222,235,247); } | |
.q2-9 { fill:rgb(198,219,239); } | |
.q3-9 { fill:rgb(158,202,225); } | |
.q4-9 { fill:rgb(107,174,214); } | |
.q5-9 { fill:rgb(66,146,198); } | |
.q6-9 { fill:rgb(33,113,181); } | |
.q7-9 { fill:rgb(8,81,156); } | |
.q8-9 { fill:rgb(8,48,107); } | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://d3js.org/queue.v1.min.js"></script> | |
<script src="http://d3js.org/topojson.v1.min.js"></script> | |
<script> | |
states = {"wa": 4882, "bc": 2914, "va": 6611, "de": 739, "dc": 1595, "wi": 4591, "wv": 474, | |
"hi": 543, "co": 5111, "fl": 6676, "fm": 2, "wy": 249, "nh": 4469, "sk": 350, | |
"nj": 5860, "pq": 1344, "nl": 96, "nm": 720, "tx": 9662, "la": 734, "nb": 679, | |
"nc": 4737, "nd": 296, "ne": 837, "nf": 113, "yt": 23, "tn": 2407, "ny": 15299, | |
"pa": 9399, "pe": 194, "ns": 1102, "nt": 13, "ca": 19467, "nv": 850, "aa": 12, | |
"pr": 374, "gu": 7, "ab": 2338, "ae": 75, "pw": 1, "on": 11940, "vi": 27, "ak": 554, | |
"oh": 8111, "al": 1028, "ap": 19, "as": 1, "ar": 567, "vt": 1443, "il": 10158, | |
"ga": 3682, "in": 3009, "ia": 1693, "ok": 898, "az": 2686, "id": 873, "ct": 5082, | |
"me": 2222, "md": 4941, "ma": 58667, "mb": 437, "ut": 3240, "mo": 2298, "mn": 5102, | |
"mi": 7184, "ri": 1968, "ks": 1491, "mt": 563, "qc": 1527, "ms": 395, "sc": 1532, | |
"ky": 1399, "or": 3160, "sd": 269}; | |
statecodes = { | |
"30": { "id": "30", "name": "montana", "two": "mt", "population": 989415 }, | |
"54": { "id": "54", "name": "west virginia", "two": "wv", "population": 1852994 }, | |
"42": { "id": "42", "name": "pennsylvania", "two": "pa", "population": 12702379 }, | |
"48": { "id": "48", "name": "texas", "two": "tx", "population": 25145561 }, | |
"45": { "id": "45", "name": "south carolina", "two": "sc", "population": 4625364 }, | |
"50": { "id": "50", "name": "vermont", "two": "vt", "population": 625741 }, | |
"60": { "id": "60", "name": "american samoa", "two": "as", "population": 55519 }, | |
"49": { "id": "49", "name": "utah", "two": "ut", "population": 2763885 }, | |
"66": { "id": "66", "name": "guam", "two": "gu", "population": 159358 }, | |
"69": { "id": "69", "name": "northern mariana islands", "two": "mp", "population": 53883 }, | |
"53": { "id": "53", "name": "washington", "two": "wa", "population": 6724540 }, | |
"02": { "id": "02", "name": "alaska", "two": "ak", "population": 710231 }, | |
"25": { "id": "25", "name": "massachusetts", "two": "ma", "population": 6547629 }, | |
"26": { "id": "26", "name": "michigan", "two": "mi", "population": 9883640 }, | |
"01": { "id": "01", "name": "alabama", "two": "al", "population": 4779736 }, | |
"06": { "id": "06", "name": "california", "two": "ca", "population": 37253956 }, | |
"21": { "id": "21", "name": "kentucky", "two": "ky", "population": 4339367 }, | |
"04": { "id": "04", "name": "arizona", "two": "az", "population": 6392017 }, | |
"05": { "id": "05", "name": "arkansas", "two": "ar", "population": 2915918 }, | |
"46": { "id": "46", "name": "south dakota", "two": "sd", "population": 814180 }, | |
"47": { "id": "47", "name": "tennessee", "two": "tn", "population": 6346105 }, | |
"08": { "id": "08", "name": "colorado", "two": "co", "population": 5029196 }, | |
"09": { "id": "09", "name": "connecticut", "two": "ct", "population": 3574097 }, | |
"28": { "id": "28", "name": "mississippi", "two": "ms", "population": 2967297 }, | |
"29": { "id": "29", "name": "missouri", "two": "mo", "population": 5988927 }, | |
"40": { "id": "40", "name": "oklahoma", "two": "ok", "population": 3751351 }, | |
"41": { "id": "41", "name": "oregon", "two": "or", "population": 3831074 }, | |
"51": { "id": "51", "name": "virginia", "two": "va", "population": 8001024 }, | |
"24": { "id": "24", "name": "maryland", "two": "md", "population": 5773552 }, | |
"56": { "id": "56", "name": "wyoming", "two": "wy", "population": 563626 }, | |
"39": { "id": "39", "name": "ohio", "two": "oh", "population": 11536504 }, | |
"27": { "id": "27", "name": "minnesota", "two": "mn", "population": 5303925 }, | |
"72": { "id": "72", "name": "puerto rico", "two": "pr", "population": 3725789 }, | |
"20": { "id": "20", "name": "kansas", "two": "ks", "population": 2853118 }, | |
"38": { "id": "38", "name": "north dakota", "two": "nd", "population": 672591 }, | |
"78": { "id": "78", "name": "u.s. virgin islands", "two": "vi", "population": 106405 }, | |
"11": { "id": "11", "name": "district of columbia", "two": "dc", "population": 601723 }, | |
"10": { "id": "10", "name": "delaware", "two": "de", "population": 897934 }, | |
"13": { "id": "13", "name": "georgia", "two": "ga", "population": 9687653 }, | |
"12": { "id": "12", "name": "florida", "two": "fl", "population": 18801310 }, | |
"15": { "id": "15", "name": "hawaii", "two": "hi", "population": 1360301 }, | |
"22": { "id": "22", "name": "louisiana", "two": "la", "population": 4533372 }, | |
"17": { "id": "17", "name": "illinois", "two": "il", "population": 12830632 }, | |
"16": { "id": "16", "name": "idaho", "two": "id", "population": 1567582 }, | |
"19": { "id": "19", "name": "iowa", "two": "ia", "population": 3046355 }, | |
"18": { "id": "18", "name": "indiana", "two": "in", "population": 6483802 }, | |
"31": { "id": "31", "name": "nebraska", "two": "ne", "population": 1826341 }, | |
"23": { "id": "23", "name": "maine", "two": "me", "population": 1328361 }, | |
"37": { "id": "37", "name": "north carolina", "two": "nc", "population": 9535483 }, | |
"36": { "id": "36", "name": "new york", "two": "ny", "population": 19378102 }, | |
"35": { "id": "35", "name": "new mexico", "two": "nm", "population": 2059179 }, | |
"34": { "id": "34", "name": "new jersey", "two": "nj", "population": 8791894 }, | |
"33": { "id": "33", "name": "new hampshire", "two": "nh", "population": 1316470 }, | |
"55": { "id": "55", "name": "wisconsin", "two": "wi", "population": 5686986 }, | |
"74": { "id": "74", "name": "u.s. minor outlying islands", "two": "um", "population": 300 }, | |
"32": { "id": "32", "name": "nevada", "two": "nv", "population": 2700551 }, | |
"44": { "id": "44", "name": "rhode island", "two": "ri", "population": 1052567 } | |
} | |
var width = 960, | |
height = 600; | |
var percapita = function(d) { return states[d["two"]] / d.population; } | |
var runnerpop = d3.values(statecodes).map(percapita); | |
var maxvalue = d3.max(runnerpop); | |
var minvalue = d3.min(runnerpop); | |
var logscale = d3.scale.log().domain([minvalue,maxvalue]).rangeRound([0,8]); | |
function quantize(i) { | |
return "q" + logscale(i) + "-9"; | |
} | |
var projection = d3.geo.albersUsa() | |
.scale(1280) | |
.translate([width / 2, height / 2]); | |
var path = d3.geo.path() | |
.projection(projection); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
queue() | |
.defer(d3.json, "us.json") | |
.await(ready); | |
function ready(error, us) { | |
var pad = d3.format("02d"); | |
function colorize(d) { | |
var state = statecodes[pad(d.id)] | |
var percapita = states[state.two] / state.population; | |
return quantize(percapita); | |
} | |
svg.append("g") | |
.attr("class", "states2") | |
.selectAll("path") | |
.data(topojson.feature(us, us.objects.states).features) | |
.enter().append("path") | |
.attr("class", colorize) | |
.attr("d", path); | |
} | |
d3.select(self.frameElement).style("height", height + "px"); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment