var margin = {top: 20, right: 20, bottom: 20, left: 20}; width = 800 - margin.left - margin.right, height = 500 - margin.top - margin.bottom, formatSubtraction = d3.format("100"); var svg = d3.select("#map").append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); tooltip = d3.select("body").append("div") .attr("class", "tooltip") .style("opacity", 0); queue() .defer(d3.csv, "lyme-data.csv") .defer(d3.json, "us.json") .await(ready); var legendText = ["", "10", "", "15", "", "20", "", "25"]; var legendColors = ['#ffe4b5','#f1ce9f','#e3b989','#d5a575','#c79061','#b97c4d','#ab683b','#a0522d' ]; function ready(error, data, us) { var counties = topojson.feature(us, us.objects.counties); data.forEach(function(d) { d.year = +d.year; d.fips = +d.fips; d.rate = +d.rate; }); var dataByCountyByYear = d3.nest() .key(function(d) { return d.fips; }) .key(function(d) { return d.year; }) .map(data); counties.features.forEach(function(county) { county.properties.years = dataByCountyByYear[+county.id] }); var color = d3.scale.threshold() .domain([10, 12.5, 15, 17.5, 20, 22.5, 25]) .range(['#ffe4b5','#f1ce9f','#e3b989','#d5a575','#c79061','#b97c4d','#ab683b','#a0522d' ]); var projection = d3.geo.albersUsa() .translate([width / 2, height / 2]); var path = d3.geo.path() .projection(projection); var countyShapes = svg.selectAll(".county") .data(counties.features) .enter() .append("path") .attr("class", "county") .attr("d", path); countyShapes .on("mouseover", function(d) { tooltip.transition() .duration(250) .style("opacity", 1); tooltip.html( "
" + d.properties.years[2000][0].county + ", " + d.properties.years[2000][0].state + "
" + "| Reported Lyme Cases in 2000: | " + formatSubtraction((d.properties.years[2000][0].rate)) + " |
| Reported Lyme Cases in 2015: | " + formatSubtraction((d.properties.years[2015][0].rate)) + " |
| Change: | " + formatSubtraction((d.properties.years[2015][0].rate-d.properties.years[2000][0].rate)) + " |