Skip to content

Instantly share code, notes, and snippets.

@jalapic
Last active September 3, 2015 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jalapic/21876b3da3c2f98a87ef to your computer and use it in GitHub Desktop.
Save jalapic/21876b3da3c2f98a87ef to your computer and use it in GitHub Desktop.
Stop and Frisk NYC 2014
<!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>
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