This choropleth encodes the area of each county using color on a log scale from red to blue.
-
-
Save callumacrae/56ac86b9129e1098eba7af9b49f6ab10 to your computer and use it in GitHub Desktop.
Area Choropleth
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
license: gpl-3.0 |
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
.states { | |
fill: none; | |
stroke: #fff; | |
stroke-linejoin: round; | |
} | |
</style> | |
<body> | |
<script src="//d3js.org/d3.v3.min.js"></script> | |
<script src="//d3js.org/topojson.v1.min.js"></script> | |
<script> | |
var width = 960, | |
height = 500; | |
var fill = d3.scale.log() | |
.domain([10, 500]) | |
.range(["white", "rgb(38, 93, 171)"]); | |
var path = d3.geo.path(); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
d3.json("/mbostock/raw/4090846/us.json", function(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("d", path) | |
.style("fill", function(d) { return fill(path.area(d)); }); | |
svg.append("path") | |
.datum(topojson.mesh(us, us.objects.states, function(a, b) { return a.id !== b.id; })) | |
.attr("class", "states") | |
.attr("d", path); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment