This choropleth encodes unemployment rates from 2008 with a quantize scale ranging from 0 to 15%. A threshold scale is a useful alternative for coloring arbitrary ranges.
forked from mbostock's block: Choropleth
xxxxxxxxxx
<meta charset="utf-8">
<style>
.counties {
fill: none;
}
.states {
fill: none;
stroke: #fff;
stroke-linejoin: round;
}
.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>
<head>
</head>
<body onload="sizeChange()">
<div class="container">
</div>
</body>
<script src="//d3js.org/d3.v4.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js'></script>
<script>
var svg = d3.select(".container")
.append("svg")
.attr("width", "100%")
var rateById = d3.map();
var quantize = d3.scaleQuantize()
.domain([0, 0.15])
.range(d3.range(9).map(function(i) { return "q" + i + "-9"; }));
var projection = d3.geoAlbersUsa()
.scale(900);
var path = d3.geoPath()
.projection(projection);
d3.queue()
.defer(d3.json, "https://gist.githubusercontent.com/mbostock/4090846/raw/d534aba169207548a8a3d670c9c2cc719ff05c47/us.json")
.defer(d3.tsv, "unemployment.tsv", function(d) { rateById.set(d.id, +d.rate); })
.await(ready);
function ready(error, us) {
if (error) throw error;
svg.append("g")
.attr("class", "counties")
.selectAll("path")
.data(topojson.feature(us, us.objects.counties).features)
.enter().append("path")
.attr("class", function(d) { return quantize(rateById.get(d.id)); })
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(us, us.objects.states, function(a, b) { return a !== b; }))
.attr("class", "states")
.attr("d", path);
}
function sizeChange() {
d3.select("g").attr("transform", "scale(" + $(".container").width()/900 + ")");
$("svg").height($(".container").width()*0.618);
}
</script>
Modified http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js to a secure url
https://d3js.org/d3.v4.min.js
https://d3js.org/topojson.v1.min.js
https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js