Last active
September 3, 2015 03:55
-
-
Save jalapic/21876b3da3c2f98a87ef to your computer and use it in GitHub Desktop.
Stop and Frisk NYC 2014
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> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Adding Tooltips</title> | |
<h1>Stop and Frisk Totals by Race for NYC in 2014 </h1> | |
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script> | |
<style type="text/css"> | |
h1{ | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 26px; | |
font-style: bold; | |
} | |
body { | |
background-color: #F9FFFF; | |
} | |
svg { | |
background-color: #F9FFFF; | |
} | |
.myrect { | |
fill: #191970; | |
} | |
.myrect:hover { | |
fill: #af1e23; | |
} | |
</style> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
var svg = d3.select("body") | |
.append("svg") | |
.attr("width", 500) | |
.attr("height", 200); | |
d3.csv("stopfrisksum.csv", function(data) { | |
data.sort(function(a, b) { | |
return d3.descending(+a.total, +b.total); | |
}); | |
var rects = svg.selectAll("rect") | |
.data(data) | |
.enter() | |
.append("rect"); | |
rects.attr("class", "myrect") | |
.attr("x", 0) | |
.attr("y", function(d, i) { | |
return i * 20; | |
}) | |
.attr("width", function(d) { | |
return d.total / 50; | |
}) | |
.attr("height", 15) | |
.append("title") | |
.text(function(d) { | |
return d.race + " individuals were stopped and frisked " + d.total + " times in NYC in 2014"; | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
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
race | Bronx | Brooklyn | Manhattan | Queens | Staten_Island | total | |
---|---|---|---|---|---|---|---|
AMERICAN INDIAN/ALASKAN NATIVE | 16 | 23 | 14 | 115 | 17 | 185 | |
ASIAN/PACIFIC ISLANDER | 39 | 332 | 138 | 1594 | 70 | 2173 | |
BLACK | 3182 | 8696 | 3434 | 5688 | 2468 | 23468 | |
BLACK-HISPANIC | 839 | 547 | 661 | 478 | 158 | 2683 | |
OTHER | 143 | 160 | 239 | 107 | 57 | 706 | |
WHITE | 199 | 1243 | 711 | 1715 | 1259 | 5127 | |
WHITE-HISPANIC | 2115 | 1978 | 1563 | 2919 | 735 | 9310 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment