Last active
August 29, 2015 14:01
-
-
Save jrrickard/fb531d871c5203a216d0 to your computer and use it in GitHub Desktop.
Version two of the choropleth, with files run through mapshaper.
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
county | percent | |
---|---|---|
Jefferson | 0.003768843 | |
El Paso | 0.873115576 | |
Pitkin | 0.001256281 | |
Boulder | 0.003768843 | |
Arapahoe | 0.015075377 | |
Fremont | 0.003768844 | |
Douglas | 0.011306533 | |
Adams | 0.003768843 | |
Denver | 0.011306533 | |
Teller | 0.030150754 | |
Elbert | 0.003768844 | |
Larimer | 0.003768844 | |
Park | 0.001256281 | |
Pueblo | 0.030150754 |
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
county | featureId | |
---|---|---|
Adams | 001 | |
Jefferson | 059 | |
El Paso | 041 | |
Pitkin | 097 | |
Boulder | 013 | |
Arapahoe | 005 | |
Fremont | 043 | |
Douglas | 035 | |
Denver | 031 | |
Teller | 119 | |
Elbert | 039 | |
Larimer | 069 | |
Park | 093 | |
Pueblo | 101 |
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> | |
.overlay { | |
fill: none; | |
pointer-events: all; | |
} | |
.border { | |
fill: none; | |
stroke: #000000; | |
stroke-linejoin: round; | |
stroke-linecap: round; | |
} | |
.color0 { stroke: #000000; fill:#FFFAFA; } | |
.color1 { stroke: #000000; fill:#F4C2C2; } | |
.color3 { stroke: #000000; fill:#FF6961; } | |
.color4 { stroke: #000000; fill:#FF5C5C; } | |
.color5 { stroke: #000000; fill#FF1C00; } | |
.color6 { stroke: #000000; fill:#FF0800; } | |
.color7 { stroke: #000000; fill:#FF0000; } | |
.color8 { stroke: #000000; fill:#CD5C5C; } | |
.color9 { stroke: #000000; fill:#E34234; } | |
.color10 { stroke: #000000; fill:#D73B3E; } | |
.color11 { stroke: #000000; fill:#CE1620; } | |
.color12 { stroke: #000000; fill:#CC0000; } | |
.color13 { stroke: #000000; fill:#B22222; } | |
.color14 { stroke: #000000; fill:#B31B1B; } | |
.color15 { stroke: #000000; fill:#A40000; } | |
.color16 { stroke: #000000; fill:#800000; } | |
.color17 { stroke: #000000; fill:#701C1C; } | |
.color18 { stroke: #000000; fill:#3C1414; } | |
.color19 { stroke: #000000l fill:#321414; } | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> | |
<script src="http://d3js.org/queue.v1.min.js"></script> | |
<script src="http://d3js.org/topojson.v1.min.js"></script> | |
<script> | |
$(document).ready(function() { | |
var width = 960, height = 500; | |
var percentageByCounty = d3.map(); | |
var featureIdToCounty = d3.map(); | |
var quantize = d3.scale.quantize() | |
.domain([0, .874]) | |
.range(d3.range(20) | |
.map(function(i) { return "color" + i; })); | |
var quantize2 = d3.scale.quantize() | |
.domain([0, .04]) | |
.range(d3.range(17) | |
.map(function(i) { return "color" + i; })); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
queue() | |
.defer(d3.json, "counties.json") | |
.defer(d3.json, "colorado.json") | |
.defer(d3.csv, | |
"countyToFeatureId.csv", | |
function(d) { | |
featureIdToCounty.set(d.featureId, d.county); | |
}) | |
.defer(d3.csv, | |
"county_to_percent.csv", | |
function(d) { | |
percentageByCounty.set(d.county, +d.percent); | |
}) | |
.await(ready); | |
function ready(error, counties, states_colorado) { | |
var projection = d3.geo.albersUsa() | |
.scale(6200) | |
.translate([width*1.20,height / 1.52]); | |
svg.append("g") | |
.selectAll("path") | |
.data(counties.features) | |
.enter() | |
.append("path") | |
.attr("class",function(d) { | |
var percentage = percentageByCounty.get(d.properties.NAME); | |
if (percentage === undefined) { | |
return "border"; | |
} else { | |
if (percentage > .04) { | |
return quantize(percentage); | |
} else { | |
return quantize2(percentage); | |
} | |
} | |
}) | |
.attr("d",d3.geo.path() | |
.projection(projection)); | |
svg.append("g") | |
.selectAll("path") | |
.data(states_colorado.features) | |
.enter() | |
.append("path").attr("class","border") | |
.attr("d",d3.geo.path().projection(projection)); | |
} | |
}); | |
</script> | |
</script> |
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
choropleth using d3.js and GeoJSON files generated from TIGER data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment