Skip to content

Instantly share code, notes, and snippets.

@ginseng666
Created April 1, 2015 11: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 ginseng666/b78e44f17295d972021b to your computer and use it in GitHub Desktop.
Save ginseng666/b78e44f17295d972021b to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Exercise: Module 3</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script>
<style type="text/css">
body {
background-color: #dddddd;
} svg {
background-color: white;
}
</style>
</head>
<body>
<h1>Divorced
people in Rome
Municipalities (year 2011)</h1>
<script type="text/javascript"> var svg = d3.select("body")
.append("svg")
.attr("width", 800)
.attr("height", 382);
d3.csv("marital_status_rome_2011.csv", function(data) {
svg.selectAll("rect")
.data(data)
.enter()
.append("rect")
.attr("x", 0)
.attr("y", function(d, i) {return 2 + i * 20;}).attr("width", function(d) {return 100*(+d.Divorced/((+d.Single)+(+d.Married)+(+d.Widow)+(+d.Divorced))*100);}).attr("height", 18);
svg.selectAll("text").data(data).enter().append("text").text(function(d) {return "Municipality" + " " + d.Rome_district + " = " + d.Divorced;}).attr("x", 2).attr("y", function(d, i) {return 17 + i * 20;})
.attr("font-family", "sans-serif")
.attr("font-size", "11px")
.attr("fill", "white");
});
</script>
<p><small>Note
1: Municipality 14 was separated from Rome
in
1992<br>
Note 2: In 2013 Municipalities were reduced from 19 to 15</small></p>
</body>
</html>
Rome_district Single Married Widow Divorced
1 69988 46440 7139 4887
2 54464 53157 9666 4865
3 24480 21595 4199 1785
4 86809 94637 16384 6708
5 75557 84804 12742 4847
6 51609 56459 11100 3159
7 53101 57456 9703 3393
8 111508 118502 13729 5844
9 54721 55388 11182 4410
10 76148 88410 14070 5416
11 57388 61047 11492 4641
12 75937 84929 10678 5488
13 97967 108611 13782 7892
15 65134 71494 11583 4814
16 61600 64201 11604 4945
17 30729 29422 5763 2890
18 60988 62093 9942 4109
19 80860 86498 13296 5634
20 70317 72635 9715 5555
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment