mean (red) and total (black) rWAR by birth-state.
Last active
August 29, 2015 14:13
-
-
Save bdilday/7d1ffcc722752d26cc03 to your computer and use it in GitHub Desktop.
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"> | |
<head> | |
<title>mean and total rWAR by birth-state</title> | |
</head> | |
<style> | |
.land { | |
fill: #ddd; | |
} | |
.border { | |
fill: none; | |
stroke: #fff; | |
stroke-linejoin: round; | |
stroke-linecap: round; | |
} | |
.bubble { | |
stroke: #fff; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://d3js.org/topojson.v1.min.js"></script> | |
<script> | |
var width = 960, | |
height = 600; | |
var path = d3.geo.path() | |
.projection(null); | |
var radius = d3.scale.sqrt() | |
.domain([0, 1000]) | |
.range([0, 15]); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
d3.json("https://gist.githubusercontent.com/bdilday/7d1ffcc722752d26cc03/raw/9b30ed9b476eff35f15e5f39240b4954008727b9/us_war.json", function(error, us) { | |
//d3.json("us_war.json", function(error, us) { | |
if (error) return console.error(error); | |
console.log(us); | |
svg.append("path") | |
.datum(topojson.feature(us, us.objects.us_40)) | |
.attr("class", "land") | |
.attr("d", path); | |
svg.append("path") | |
.datum(topojson.mesh(us, us.objects.us_40, function(a, b) { return a !== b; })) | |
.attr("class", "border border--state") | |
.attr("d", path); | |
svg.append("g") | |
.attr("class", "bubble") | |
.selectAll("circle") | |
.data(topojson.feature(us, us.objects.us_40).features) | |
.enter() | |
.append("circle") | |
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; }) | |
.attr("r", function(d) { return d.properties["war"] > 100*d.properties["mwar"] ? radius(d.properties["war"]) : radius(100*d.properties["mwar"]) ; } ) | |
.attr("fill", function(d) { return d.properties["war"] > 100*d.properties["mwar"] ? "black" : "red" ;}) | |
.attr("opacity", 0.8) | |
; | |
svg.append("g") | |
.attr("class", "bubble") | |
.selectAll("circle") | |
.data(topojson.feature(us, us.objects.us_40).features) | |
.enter() | |
.append("circle") | |
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; }) | |
.attr("r", function(d) { return d.properties["war"] > 100*d.properties["mwar"] ? radius(100*d.properties["mwar"]) : radius(d.properties["war"]) ; } ) | |
.attr("fill", function(d) { return d.properties["war"] > 100*d.properties["mwar"] ? "red" : "black" ;}) | |
.attr("opacity", 0.3) | |
; | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment