This gist shows a map of Washington, D.C. divided into census tracts. Each tract is shaded according to the owner occupancy % for all households. Points of interest are indicated as red dots. A key in the lower left shows the quantize thresholds associated with each shade.
Shapefiles came from census.gov TIGER files. Owner occupancy data came from the 2012 5-year American Community Survey of the US Census. Points come from Ben Balter’s map of D.C. bars (shots are likely to have been taken at these locations).
Map projection scale created dynamically by code from Bostock’s New Jersey State Plane block.
Shading key element is Bostock’s Threshold Key block, adapted for d3.quantize().
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Washington, D.C.</title>
<style>
svg {
font: 12px sans-serif;
}
.points {
fill: red;
}
.caption {
font-weight: bold;
}
.key path {
display: none;
}
.key line {
stroke: #000;
shape-rendering: crispEdges;
}
</style>
</head>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/queue.v1.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 500,
maxscale = 7,
formatPercent = d3.format(".0%");
var rateByTract = d3.map();
var quantize = d3.scale.quantize()
.domain([0, 1])
.range(["#c6d8ef", "#9ecae1", "#6baed6", "#4292c6", "#2171b5", "#085192", "#08306b"]);
// return quantize thresholds for the key
var qrange = function(max, num) {
var a = [];
for (var i=0; i<num; i++) {
a.push(i*max/num);
}
return a;
}
var projection = d3.geo.albersUsa();
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
queue()
.defer(d3.json, "dc.json")
.defer(d3.json, "bars.json")
.defer(d3.csv, "dcdata.csv", function(d) { rateByTract.set(d.tract, (d.households>0) ? +d.owners/d.households : 0); })
.await(ready);
function ready(error, dc, bars) {
var tracts = topojson.feature(dc, dc.objects.dctracts);
// define and scale the projection so the map fits nicely in the screen
projection
.scale(1)
.translate([0, 0]);
var b = path.bounds(tracts),
s = 1.0 / Math.max((b[1][0] - b[0][0]) / width, (b[1][1] - b[0][1]) / height),
t = [(width - s * (b[1][0] + b[0][0])) / 2, (height - s * (b[1][1] + b[0][1])) / 2];
projection
.scale(s)
.translate(t);
// add census tracts
svg.selectAll("path")
.data(tracts.features)
.enter().append("path")
.attr("fill", function(d) { return quantize(rateByTract.get(d.properties.NAMELSAD)); })
.attr("d", path)
.append("title")
.text(function(d) { return d.properties.NAMELSAD; });
// add points of interest
svg.append("path")
.datum(topojson.feature(bars, bars.objects.bars))
.attr("class", "points")
.attr("d", path);
// add key
var x = d3.scale.linear()
.domain([0, 1])
.range([0, 300]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")
.tickSize(14)
.tickValues(qrange(quantize.domain()[1], quantize.range().length))
.tickFormat(function(d) { return formatPercent(d); });
var g = svg.append("g")
.attr("class", "key")
.attr("transform", "translate( 50," + height * 3 / 4 + ")");
g.selectAll("rect")
.data(quantize.range().map(function(color) {
var d = quantize.invertExtent(color);
if (d[0] == null) d[0] = x.domain()[0];
if (d[1] == null) d[1] = x.domain()[1];
return d;
}))
.enter().append("rect")
.attr("height", 10)
.attr("x", function(d) { return x(d[0]); })
.attr("width", function(d) { return x(d[1]) - x(d[0]); })
.style("fill", function(d) { return quantize(d[0]); });
g.call(xAxis).append("text")
.attr("class", "caption")
.attr("y", -6)
.text("Household owner occupancy rate");
}
</script>
</body>
</html>
{"type":"Topology","objects":{"bars":{"type":"GeometryCollection","geometries":[{"type":"Point","properties":{"marker-symbol":"bar","name":"The Exchange","address":"1719 G St NW"},"coordinates":[6780,7098]},{"type":"Point","properties":{"marker-symbol":"bar","name":"Blackfin","address":"1620 I St NW"},"coordinates":[6980,7378]},{"type":"Point","properties":{"marker-symbol":"bar","name":"Churchkey","address":"1337 14th St NW","note":"Ask the bartender for the password"},"coordinates":[7718,7978]},{"type":"Point","properties":{"marker-symbol":"bar","name":"Busboys and Poets","address":"1025 5th St NW"},"coordinates":[9281,7504]},{"type":"Point","properties":{"marker-symbol":"bar","name":"SoHo Cafe","address":"2150 P St NW"},"coordinates":[5850,8145]},{"type":"Point","properties":{"marker-symbol":"bar","name":"Chinatown Coffee Company","address":"475 H St NW"},"coordinates":[9293,7247]},{"type":"Point","properties":{"marker-symbol":"bar","name":"Science Club","address":"1136 19th St NW"},"coordinates":[6358,7748]},{"type":"Point","properties":{"marker-symbol":"bar","name":"Wonderland Ballroom","address":" 1101 Kenyon St NW"},"coordinates":[8215,9999]},{"type":"Point","properties":{"marker-symbol":"bar","name":"Tryst","address":"2459 18th St NW"},"coordinates":[6478,9279]},{"type":"Point","properties":{"marker-symbol":"bar","name":"Boundary Stone","address":"116 Rhode Island Ave NW"},"coordinates":[9999,8693]},{"type":"Point","properties":{"marker-symbol":"bar","name":"Bistro Bohem","address":"600 Florida Ave Nw"},"coordinates":[9110,8674]},{"type":"Point","properties":{"marker-symbol":"bar","name":"Old Ebbitt","address":"675 15th St NW","note":"Ask the bartender for the WiFi password"},"coordinates":[7518,7076]},{"type":"Point","properties":{"marker-symbol":"bar","name":"Capitol City Brewing Company","address":"1100 New York Ave NW","note":"Ask the bartender for the password"},"coordinates":[8227,7325]}]}},"arcs":[],"transform":{"scale":[0.000008457445744573983,0.000010808780878087963],"translate":[-77.097225,38.821598]}}
tract,households,married,singledad,singlemom,income,foodstamps,owners
Census Tract 1,5030,3032,97,55,,0,2725
Census Tract 2.01,0,0,0,0,,0,0
Census Tract 2.02,3943,1563,4,233,85417,0,2269
Census Tract 3,5399,2548,200,238,17100,11,3216
Census Tract 4,1492,1037,95,48,,0,1222
Census Tract 5.01,3098,809,0,132,27228,0,357
Census Tract 5.02,3073,1499,0,22,74000,9,1715
Census Tract 6,4039,2200,0,174,52500,0,2942
Census Tract 7.01,4470,1935,0,149,52697,0,2685
Census Tract 7.02,3184,710,168,74,26719,13,753
Census Tract 8.01,6564,3615,218,583,116047,32,3857
Census Tract 8.02,2552,1346,0,233,42212,0,1832
Census Tract 9.01,3701,2860,67,62,187750,0,3068
Census Tract 9.02,2295,1684,34,218,,0,2098
Census Tract 10.01,7378,5094,344,803,166917,0,6105
Census Tract 10.02,3130,1072,37,163,101471,0,1343
Census Tract 11,4132,2408,69,515,41815,0,3282
Census Tract 12,5135,2678,66,257,86094,16,2925
Census Tract 13.01,4113,2269,21,88,63315,0,1491
Census Tract 13.02,7635,2383,278,51,90302,40,2498
Census Tract 14.01,3467,2337,42,189,64750,17,2402
Census Tract 14.02,2904,1859,32,139,23750,0,1922
Census Tract 15,5950,4964,140,208,243520,9,5690
Census Tract 16,4237,2666,402,572,112688,0,3912
Census Tract 17.02,2711,1086,0,616,80324,0,1502
Census Tract 18.03,3305,1584,179,558,42753,15,711
Census Tract 18.04,5194,1635,1227,1048,39847,47,1377
Census Tract 19.01,3810,1545,274,1269,61098,11,2944
Census Tract 19.02,2173,988,130,747,66382,23,1580
Census Tract 20.01,2327,1135,161,557,43342,11,1265
Census Tract 20.02,3602,1274,406,904,53412,0,2598
Census Tract 21.01,5522,2429,405,1520,46474,19,3050
Census Tract 21.02,4797,1124,323,2077,42396,12,2352
Census Tract 22.01,3642,1531,77,1583,65134,0,2530
Census Tract 22.02,3472,788,264,1601,43871,4,1752
Census Tract 23.01,2820,575,261,1141,48680,0,1944
Census Tract 23.02,1348,176,47,144,65087,9,277
Census Tract 24,3625,1395,100,1254,52361,7,2334
Census Tract 25.01,2265,634,148,580,18958,0,1225
Census Tract 25.02,4977,1734,382,1275,35703,114,1786
Census Tract 26,2411,1478,83,262,100714,0,1793
Census Tract 27.01,4675,1022,358,727,48438,93,938
Census Tract 27.02,5157,2149,264,393,29946,112,2364
Census Tract 28.01,3940,993,555,911,40388,13,822
Census Tract 28.02,4584,825,779,1368,16507,71,662
Census Tract 29,4620,1322,115,1321,63682,34,1831
Census Tract 30,3438,622,251,1010,25238,0,895
Census Tract 31,3365,1091,336,912,51667,18,2354
Census Tract 32,4847,1521,396,1845,53836,63,2873
Census Tract 33.01,3006,946,198,419,80000,0,1903
Census Tract 33.02,2014,641,46,534,85069,0,1151
Census Tract 34,2635,664,336,496,34596,0,1351
Census Tract 35,2684,689,86,754,24792,25,1129
Census Tract 36,4082,650,269,1239,33571,61,1414
Census Tract 37,4179,743,159,1032,26875,23,734
Census Tract 38,4604,1194,219,258,46172,34,1375
Census Tract 39,4335,1247,203,244,39925,45,1322
Census Tract 40.01,3533,1221,115,123,120450,14,2148
Census Tract 40.02,2408,708,50,38,75393,13,974
Census Tract 41,2724,1251,112,66,68259,8,1391
Census Tract 42.01,3546,644,0,310,27321,21,1203
Census Tract 42.02,2457,623,0,50,90595,17,989
Census Tract 43,2933,818,367,172,34618,0,851
Census Tract 44,5277,1471,0,195,69000,0,2514
Census Tract 46,2630,649,205,910,43850,12,1165
Census Tract 47.01,3134,431,27,1506,12576,0,524
Census Tract 47.02,1494,245,0,335,28961,6,475
Census Tract 48.01,1972,372,104,490,39621,9,1222
Census Tract 48.02,3027,805,238,874,42132,0,496
Census Tract 49.01,2284,603,51,594,24386,0,585
Census Tract 49.02,2678,536,183,499,38646,0,822
Census Tract 50.01,1723,626,0,19,34205,0,841
Census Tract 50.02,6033,1925,542,316,17087,10,1248
Census Tract 52.01,5336,844,30,114,33514,0,2070
Census Tract 53.01,5240,1386,85,53,63587,27,2121
Census Tract 55,6434,2090,165,224,122396,69,2366
Census Tract 56,4974,904,268,100,19654,12,1515
Census Tract 58,2626,884,30,193,110500,0,1069
Census Tract 59,2411,568,0,72,24489,6,270
Census Tract 62.02,0,0,0,0,,0,0
Census Tract 64,1821,224,235,869,21509,0,401
Census Tract 65,2535,1359,30,67,77614,14,1582
Census Tract 66,1911,1057,0,0,178750,9,1016
Census Tract 67,4116,2266,173,221,56771,34,2723
Census Tract 68.01,1955,447,135,699,51838,34,1173
Census Tract 68.02,2385,961,344,459,98429,4,1453
Census Tract 68.04,0,0,0,0,,0,0
Census Tract 69,2361,1100,0,332,54651,0,1409
Census Tract 70,2165,942,49,188,38750,30,1219
Census Tract 71,3235,712,566,986,17778,8,1098
Census Tract 72,2701,722,107,333,35938,0,712
Census Tract 73.01,2377,1989,89,171,90069,6,0
Census Tract 73.04,3486,655,159,2070,33077,0,988
Census Tract 74.01,2309,249,263,1442,13165,17,244
Census Tract 74.03,3262,328,176,2312,30248,0,181
Census Tract 74.04,3442,543,193,2202,29267,0,863
Census Tract 74.06,3431,551,187,2439,29963,0,58
Census Tract 74.07,2399,489,370,1157,36806,0,808
Census Tract 74.08,2960,520,67,1968,17981,0,133
Census Tract 74.09,3788,544,299,2264,25474,0,782
Census Tract 75.02,4480,575,333,2827,28315,20,772
Census Tract 75.03,2505,390,91,1657,32024,0,697
Census Tract 75.04,2428,415,118,1437,18472,0,273
Census Tract 76.01,4232,1154,100,1869,42674,0,2788
Census Tract 76.03,3594,678,327,1361,47816,0,1540
Census Tract 76.04,3446,1183,315,878,53125,0,1649
Census Tract 76.05,3692,759,369,1628,42604,0,668
Census Tract 77.03,5439,714,500,3047,36071,0,1418
Census Tract 77.07,4275,993,390,2232,50000,0,1927
Census Tract 77.08,2683,518,236,1388,27256,0,745
Census Tract 77.09,1571,266,17,631,31359,0,533
Census Tract 78.03,2735,458,152,1278,24797,0,1065
Census Tract 78.04,2809,847,132,1317,29145,0,1381
Census Tract 78.06,2196,617,346,816,39412,0,1149
Census Tract 78.07,2245,649,110,1155,21867,0,646
Census Tract 78.08,4490,835,381,2657,34135,0,1487
Census Tract 78.09,2531,289,241,1358,33025,13,1033
Census Tract 79.01,4205,495,650,2153,24847,0,1320
Census Tract 79.03,1569,474,135,484,39583,0,1016
Census Tract 80.01,2682,801,187,644,54375,21,1926
Census Tract 80.02,3620,1530,150,673,43750,0,2387
Census Tract 81,3375,1488,170,570,67784,16,2331
Census Tract 82,2798,938,22,106,75478,0,1241
Census Tract 83.01,2655,801,29,327,93889,14,1506
Census Tract 83.02,2246,1071,114,40,42656,0,1353
Census Tract 84.02,2083,801,152,273,36875,0,976
Census Tract 84.10,1359,332,279,368,94028,0,874
Census Tract 87.01,1982,223,37,926,43950,0,1085
Census Tract 87.02,1830,271,246,680,56397,28,975
Census Tract 88.02,4516,829,314,1971,30809,7,1834
Census Tract 88.03,1049,194,12,481,17963,0,203
Census Tract 88.04,2815,314,422,1284,25887,0,1176
Census Tract 89.03,2682,221,71,1680,30350,0,646
Census Tract 89.04,3209,468,421,1295,24500,21,473
Census Tract 90,2781,471,198,814,36442,18,1203
Census Tract 91.02,4489,1016,106,2564,31219,0,1876
Census Tract 92.01,1259,365,39,523,51357,0,461
Census Tract 92.03,2557,547,131,885,44706,8,1357
Census Tract 92.04,2609,612,255,867,20078,49,486
Census Tract 93.01,3067,1407,99,920,55114,11,2267
Census Tract 93.02,1140,489,68,285,63125,5,856
Census Tract 94,4059,1392,171,1537,63909,0,2921
Census Tract 95.01,4436,1456,383,1428,46250,48,1058
Census Tract 95.03,2978,1290,75,1128,74432,8,2563
Census Tract 95.04,2484,413,524,914,52917,0,1235
Census Tract 95.05,2782,1117,242,950,70667,0,2115
Census Tract 95.07,1443,437,34,626,49519,6,1254
Census Tract 95.08,3236,1368,215,745,55804,0,1907
Census Tract 95.09,3057,1479,333,760,67642,0,2594
Census Tract 96.01,2686,893,53,1509,35711,0,860
Census Tract 96.02,2928,156,154,2061,20773,0,300
Census Tract 96.03,2876,236,283,1291,40543,0,907
Census Tract 96.04,2061,489,110,771,46042,0,1523
Census Tract 97,2762,427,221,1870,26780,0,1016
Census Tract 98.01,1764,132,113,1240,29539,0,181
Census Tract 98.02,1209,109,0,761,22396,0,233
Census Tract 98.03,2451,384,272,1067,19521,0,522
Census Tract 98.04,2766,566,155,1532,47107,0,1107
Census Tract 98.07,3024,541,283,1509,38813,21,1491
Census Tract 98.10,2158,50,100,1416,27019,0,78
Census Tract 98.11,4104,362,610,2209,24481,0,245
Census Tract 99.01,2214,1347,132,314,83033,0,1772
Census Tract 99.02,2690,424,187,1557,53520,0,2154
Census Tract 99.03,1319,123,125,719,55691,0,676
Census Tract 99.04,1489,296,183,562,38920,6,461
Census Tract 99.05,2496,797,87,1086,37226,0,1097
Census Tract 99.06,1441,598,76,525,41088,0,809
Census Tract 99.07,2676,410,114,1726,23661,0,663
Census Tract 101,2548,793,0,0,38864,0,638
Census Tract 102,2417,638,27,555,85341,0,869
Census Tract 103,2892,950,257,957,62216,0,1385
Census Tract 104,3914,913,449,1816,39622,5,1662
Census Tract 105,4132,873,238,820,41083,49,899
Census Tract 106,3983,890,203,795,56786,0,1772
Census Tract 107,1862,298,0,59,49875,0,347
Census Tract 108,1533,124,0,40,7022,21,69
Census Tract 109,2913,274,138,1888,32202,0,164
Census Tract 110,3278,702,88,481,86410,31,2173
Census Tract 111,4290,1618,204,1543,53125,0,2992