A variant of Mike Bostock's small multiples example which, instead of resetting the domain of the y-scale every time it is used, creates a separate y-scale for each multiple.
This a version tailored for a project for UN Global Pulse.
A variant of Mike Bostock's small multiples example which, instead of resetting the domain of the y-scale every time it is used, creates a separate y-scale for each multiple.
This a version tailored for a project for UN Global Pulse.
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300' rel='stylesheet' type='text/css'> | |
<style> | |
body { | |
font: 10px 'Open Sans'; | |
margin: 0; | |
} | |
.line { | |
fill: none; | |
stroke: #00aeef; | |
stroke-width: 1.5px; | |
} | |
.area { | |
fill: #e1f4fd; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script> | |
var margin = {top: 8, right: 10, bottom: 2, left: 10}, | |
width = 960 - margin.left - margin.right, | |
height = 69 - margin.top - margin.bottom; | |
var parseDate = d3.time.format("%b %Y").parse; | |
//var parseDate = d3.time.format("%Y-%d").parse; | |
var x = d3.time.scale() | |
.range([0, width]); | |
d3.csv("post2015.csv", type, function(error, data) { | |
var groups = d3.nest() | |
.key(function(d) { return d.group; }) | |
.entries(data); | |
x.domain([ | |
d3.min(groups, function(group) { return group.values[0].date; }), | |
d3.max(groups, function(group) { return group.values[group.values.length - 1].date; }) | |
]); | |
var svg = d3.select("body").selectAll("svg") | |
.data(groups) | |
.enter().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 + ")") | |
.each(function(group) { | |
group.y = d3.scale.linear() | |
.domain([0, d3.max(group.values, function(d) { return d.tweets; })]) | |
.range([height, 0]); | |
}); | |
svg.append("path") | |
.attr("class", "area") | |
.attr("d", function(group) { | |
return d3.svg.area() | |
.x(function(d) { return x(d.date); }) | |
.y1(function(d) { return group.y(d.tweets); }) | |
.y0(height) | |
(group.values); | |
}); | |
svg.append("path") | |
.attr("class", "line") | |
.attr("d", function(group) { | |
return d3.svg.line() | |
.x(function(d) { return x(d.date); }) | |
.y(function(d) { return group.y(d.tweets); }) | |
(group.values); | |
}); | |
svg.append("text") | |
.attr("x", width - 6) | |
.attr("y", height - 6) | |
.style("text-anchor", "end") | |
.text(function(group) { return group.key; }); | |
}); | |
function type(d) { | |
d.tweets = +d.tweets; | |
d.date = parseDate(d.date); | |
return d; | |
} | |
</script> |
group | date | tweets | |
---|---|---|---|
A good education | Aug 2012 | 517530 | |
A good education | Sep 2012 | 506419 | |
A good education | Oct 2012 | 557342 | |
A good education | Nov 2012 | 440303 | |
A good education | Dec 2012 | 416928 | |
A good education | Jan 2013 | 490158 | |
A good education | Feb 2013 | 356814 | |
A good education | Mar 2013 | 532401 | |
A good education | Apr 2013 | 623465 | |
A good education | May 2013 | 608586 | |
A good education | Jun 2013 | 733397 | |
A good education | Jul 2013 | 584675 | |
A good education | Aug 2013 | 618259 | |
A good education | Sep 2013 | 713803 | |
A good education | Oct 2013 | 697446 | |
A good education | Nov 2013 | 575108 | |
A good education | Dec 2013 | 487810 | |
A good education | Jan 2014 | 598983 | |
A good education | Feb 2014 | 471582 | |
A good education | Mar 2014 | 658008 | |
A good education | Apr 2014 | 834438 | |
A good education | May 2014 | 901189 | |
Access to clean water and sanitation | Aug 2012 | 70143 | |
Access to clean water and sanitation | Sep 2012 | 53147 | |
Access to clean water and sanitation | Oct 2012 | 62388 | |
Access to clean water and sanitation | Nov 2012 | 55235 | |
Access to clean water and sanitation | Dec 2012 | 47688 | |
Access to clean water and sanitation | Jan 2013 | 62857 | |
Access to clean water and sanitation | Feb 2013 | 44701 | |
Access to clean water and sanitation | Mar 2013 | 162772 | |
Access to clean water and sanitation | Apr 2013 | 89593 | |
Access to clean water and sanitation | May 2013 | 77955 | |
Access to clean water and sanitation | Jun 2013 | 75477 | |
Access to clean water and sanitation | Jul 2013 | 91859 | |
Access to clean water and sanitation | Aug 2013 | 97648 | |
Access to clean water and sanitation | Sep 2013 | 119479 | |
Access to clean water and sanitation | Oct 2013 | 77189 | |
Access to clean water and sanitation | Nov 2013 | 133001 | |
Access to clean water and sanitation | Dec 2013 | 77519 | |
Access to clean water and sanitation | Jan 2014 | 86316 | |
Access to clean water and sanitation | Feb 2014 | 72433 | |
Access to clean water and sanitation | Mar 2014 | 144012 | |
Access to clean water and sanitation | Apr 2014 | 142397 | |
Access to clean water and sanitation | May 2014 | 146017 | |
Action taken on climate change | Aug 2012 | 159544 | |
Action taken on climate change | Sep 2012 | 133907 | |
Action taken on climate change | Oct 2012 | 191952 | |
Action taken on climate change | Nov 2012 | 221173 | |
Action taken on climate change | Dec 2012 | 183765 | |
Action taken on climate change | Jan 2013 | 216644 | |
Action taken on climate change | Feb 2013 | 124646 | |
Action taken on climate change | Mar 2013 | 215110 | |
Action taken on climate change | Apr 2013 | 199278 | |
Action taken on climate change | May 2013 | 195353 | |
Action taken on climate change | Jun 2013 | 208604 | |
Action taken on climate change | Jul 2013 | 194228 | |
Action taken on climate change | Aug 2013 | 191880 | |
Action taken on climate change | Sep 2013 | 247555 | |
Action taken on climate change | Oct 2013 | 184041 | |
Action taken on climate change | Nov 2013 | 248682 | |
Action taken on climate change | Dec 2013 | 199309 | |
Action taken on climate change | Jan 2014 | 359412 | |
Action taken on climate change | Feb 2014 | 203567 | |
Action taken on climate change | Mar 2014 | 274492 | |
Action taken on climate change | Apr 2014 | 326167 | |
Action taken on climate change | May 2014 | 386445 | |
Affordable and nutritious food | Aug 2012 | 87030 | |
Affordable and nutritious food | Sep 2012 | 86798 | |
Affordable and nutritious food | Oct 2012 | 97599 | |
Affordable and nutritious food | Nov 2012 | 59327 | |
Affordable and nutritious food | Dec 2012 | 60926 | |
Affordable and nutritious food | Jan 2013 | 83092 | |
Affordable and nutritious food | Feb 2013 | 56593 | |
Affordable and nutritious food | Mar 2013 | 93502 | |
Affordable and nutritious food | Apr 2013 | 81551 | |
Affordable and nutritious food | May 2013 | 103285 | |
Affordable and nutritious food | Jun 2013 | 110074 | |
Affordable and nutritious food | Jul 2013 | 107984 | |
Affordable and nutritious food | Aug 2013 | 119837 | |
Affordable and nutritious food | Sep 2013 | 103568 | |
Affordable and nutritious food | Oct 2013 | 115831 | |
Affordable and nutritious food | Nov 2013 | 94998 | |
Affordable and nutritious food | Dec 2013 | 79663 | |
Affordable and nutritious food | Jan 2014 | 93962 | |
Affordable and nutritious food | Feb 2014 | 74786 | |
Affordable and nutritious food | Mar 2014 | 119399 | |
Affordable and nutritious food | Apr 2014 | 152623 | |
Affordable and nutritious food | May 2014 | 129579 | |
An honest and responsive government | Aug 2012 | 407623 | |
An honest and responsive government | Sep 2012 | 428853 | |
An honest and responsive government | Oct 2012 | 558876 | |
An honest and responsive government | Nov 2012 | 471688 | |
An honest and responsive government | Dec 2012 | 502232 | |
An honest and responsive government | Jan 2013 | 680874 | |
An honest and responsive government | Feb 2013 | 606936 | |
An honest and responsive government | Mar 2013 | 599309 | |
An honest and responsive government | Apr 2013 | 1006128 | |
An honest and responsive government | May 2013 | 894222 | |
An honest and responsive government | Jun 2013 | 1209088 | |
An honest and responsive government | Jul 2013 | 994940 | |
An honest and responsive government | Aug 2013 | 1114995 | |
An honest and responsive government | Sep 2013 | 732836 | |
An honest and responsive government | Oct 2013 | 889227 | |
An honest and responsive government | Nov 2013 | 859882 | |
An honest and responsive government | Dec 2013 | 778099 | |
An honest and responsive government | Jan 2014 | 755183 | |
An honest and responsive government | Feb 2014 | 765542 | |
An honest and responsive government | Mar 2014 | 1009253 | |
An honest and responsive government | Apr 2014 | 1014630 | |
An honest and responsive government | May 2014 | 1140565 | |
Better healthcare | Aug 2012 | 56131 | |
Better healthcare | Sep 2012 | 64683 | |
Better healthcare | Oct 2012 | 73377 | |
Better healthcare | Nov 2012 | 81442 | |
Better healthcare | Dec 2012 | 53758 | |
Better healthcare | Jan 2013 | 77165 | |
Better healthcare | Feb 2013 | 40360 | |
Better healthcare | Mar 2013 | 68833 | |
Better healthcare | Apr 2013 | 84647 | |
Better healthcare | May 2013 | 83698 | |
Better healthcare | Jun 2013 | 77047 | |
Better healthcare | Jul 2013 | 79827 | |
Better healthcare | Aug 2013 | 70985 | |
Better healthcare | Sep 2013 | 102582 | |
Better healthcare | Oct 2013 | 134039 | |
Better healthcare | Nov 2013 | 100121 | |
Better healthcare | Dec 2013 | 78717 | |
Better healthcare | Jan 2014 | 97134 | |
Better healthcare | Feb 2014 | 69302 | |
Better healthcare | Mar 2014 | 127954 | |
Better healthcare | Apr 2014 | 133791 | |
Better healthcare | May 2014 | 1140565 | |
Better job opportunities | Aug 2012 | 607414 | |
Better job opportunities | Sep 2012 | 626676 | |
Better job opportunities | Oct 2012 | 909357 | |
Better job opportunities | Nov 2012 | 708435 | |
Better job opportunities | Dec 2012 | 555365 | |
Better job opportunities | Jan 2013 | 734753 | |
Better job opportunities | Feb 2013 | 444341 | |
Better job opportunities | Mar 2013 | 695651 | |
Better job opportunities | Apr 2013 | 798425 | |
Better job opportunities | May 2013 | 822465 | |
Better job opportunities | Jun 2013 | 682172 | |
Better job opportunities | Jul 2013 | 743813 | |
Better job opportunities | Aug 2013 | 699676 | |
Better job opportunities | Sep 2013 | 685885 | |
Better job opportunities | Oct 2013 | 680696 | |
Better job opportunities | Nov 2013 | 656723 | |
Better job opportunities | Dec 2013 | 728897 | |
Better job opportunities | Jan 2014 | 999810 | |
Better job opportunities | Feb 2014 | 577171 | |
Better job opportunities | Mar 2014 | 753002 | |
Better job opportunities | Apr 2014 | 987976 | |
Better job opportunities | May 2014 | 1018137 | |
Better transport and roads | Aug 2012 | 168559 | |
Better transport and roads | Sep 2012 | 157377 | |
Better transport and roads | Oct 2012 | 183899 | |
Better transport and roads | Nov 2012 | 175258 | |
Better transport and roads | Dec 2012 | 185833 | |
Better transport and roads | Jan 2013 | 175470 | |
Better transport and roads | Feb 2013 | 120211 | |
Better transport and roads | Mar 2013 | 249166 | |
Better transport and roads | Apr 2013 | 236813 | |
Better transport and roads | May 2013 | 197587 | |
Better transport and roads | Jun 2013 | 215110 | |
Better transport and roads | Jul 2013 | 195280 | |
Better transport and roads | Aug 2013 | 192443 | |
Better transport and roads | Sep 2013 | 182889 | |
Better transport and roads | Oct 2013 | 192712 | |
Better transport and roads | Nov 2013 | 193906 | |
Better transport and roads | Dec 2013 | 191527 | |
Better transport and roads | Jan 2014 | 222299 | |
Better transport and roads | Feb 2014 | 174245 | |
Better transport and roads | Mar 2014 | 198686 | |
Better transport and roads | Apr 2014 | 245226 | |
Better transport and roads | May 2014 | 228911 | |
Equality between men and women | Aug 2012 | 129716 | |
Equality between men and women | Sep 2012 | 128547 | |
Equality between men and women | Oct 2012 | 244694 | |
Equality between men and women | Nov 2012 | 222731 | |
Equality between men and women | Dec 2012 | 168227 | |
Equality between men and women | Jan 2013 | 181702 | |
Equality between men and women | Feb 2013 | 186242 | |
Equality between men and women | Mar 2013 | 292995 | |
Equality between men and women | Apr 2013 | 214813 | |
Equality between men and women | May 2013 | 207217 | |
Equality between men and women | Jun 2013 | 205758 | |
Equality between men and women | Jul 2013 | 198631 | |
Equality between men and women | Aug 2013 | 178133 | |
Equality between men and women | Sep 2013 | 186245 | |
Equality between men and women | Oct 2013 | 194042 | |
Equality between men and women | Nov 2013 | 358991 | |
Equality between men and women | Dec 2013 | 207577 | |
Equality between men and women | Jan 2014 | 235322 | |
Equality between men and women | Feb 2014 | 182180 | |
Equality between men and women | Mar 2014 | 356667 | |
Equality between men and women | Apr 2014 | 403157 | |
Equality between men and women | May 2014 | 387394 | |
Freedom from discrimination | Aug 2012 | 504654 | |
Freedom from discrimination | Sep 2012 | 426125 | |
Freedom from discrimination | Oct 2012 | 439692 | |
Freedom from discrimination | Nov 2012 | 659612 | |
Freedom from discrimination | Dec 2012 | 503169 | |
Freedom from discrimination | Jan 2013 | 489770 | |
Freedom from discrimination | Feb 2013 | 516804 | |
Freedom from discrimination | Mar 2013 | 1083682 | |
Freedom from discrimination | Apr 2013 | 886839 | |
Freedom from discrimination | May 2013 | 854445 | |
Freedom from discrimination | Jun 2013 | 830493 | |
Freedom from discrimination | Jul 2013 | 619101 | |
Freedom from discrimination | Aug 2013 | 603292 | |
Freedom from discrimination | Sep 2013 | 426416 | |
Freedom from discrimination | Oct 2013 | 489476 | |
Freedom from discrimination | Nov 2013 | 523389 | |
Freedom from discrimination | Dec 2013 | 546047 | |
Freedom from discrimination | Jan 2014 | 609767 | |
Freedom from discrimination | Feb 2014 | 656922 | |
Freedom from discrimination | Mar 2014 | 613677 | |
Freedom from discrimination | Apr 2014 | 658967 | |
Freedom from discrimination | May 2014 | 902772 | |
Phone and internet access | Aug 2012 | 229786 | |
Phone and internet access | Sep 2012 | 186044 | |
Phone and internet access | Oct 2012 | 242329 | |
Phone and internet access | Nov 2012 | 226924 | |
Phone and internet access | Dec 2012 | 228978 | |
Phone and internet access | Jan 2013 | 243982 | |
Phone and internet access | Feb 2013 | 175023 | |
Phone and internet access | Mar 2013 | 292986 | |
Phone and internet access | Apr 2013 | 327124 | |
Phone and internet access | May 2013 | 288099 | |
Phone and internet access | Jun 2013 | 290147 | |
Phone and internet access | Jul 2013 | 317821 | |
Phone and internet access | Aug 2013 | 319277 | |
Phone and internet access | Sep 2013 | 279150 | |
Phone and internet access | Oct 2013 | 260016 | |
Phone and internet access | Nov 2013 | 246990 | |
Phone and internet access | Dec 2013 | 241560 | |
Phone and internet access | Jan 2014 | 255273 | |
Phone and internet access | Feb 2014 | 187736 | |
Phone and internet access | Mar 2014 | 242194 | |
Phone and internet access | Apr 2014 | 326002 | |
Phone and internet access | May 2014 | 266022 | |
Political freedoms | Aug 2012 | 245480 | |
Political freedoms | Sep 2012 | 264316 | |
Political freedoms | Oct 2012 | 331876 | |
Political freedoms | Nov 2012 | 308335 | |
Political freedoms | Dec 2012 | 259535 | |
Political freedoms | Jan 2013 | 278806 | |
Political freedoms | Feb 2013 | 184355 | |
Political freedoms | Mar 2013 | 325528 | |
Political freedoms | Apr 2013 | 354658 | |
Political freedoms | May 2013 | 497578 | |
Political freedoms | Jun 2013 | 386594 | |
Political freedoms | Jul 2013 | 361504 | |
Political freedoms | Aug 2013 | 342193 | |
Political freedoms | Sep 2013 | 285072 | |
Political freedoms | Oct 2013 | 303991 | |
Political freedoms | Nov 2013 | 279814 | |
Political freedoms | Dec 2013 | 316194 | |
Political freedoms | Jan 2014 | 358060 | |
Political freedoms | Feb 2014 | 399382 | |
Political freedoms | Mar 2014 | 403066 | |
Political freedoms | Apr 2014 | 596645 | |
Political freedoms | May 2014 | 668776 | |
Protecting forests rivers and oceans | Aug 2012 | 216031 | |
Protecting forests rivers and oceans | Sep 2012 | 215094 | |
Protecting forests rivers and oceans | Oct 2012 | 256999 | |
Protecting forests rivers and oceans | Nov 2012 | 226089 | |
Protecting forests rivers and oceans | Dec 2012 | 209766 | |
Protecting forests rivers and oceans | Jan 2013 | 257870 | |
Protecting forests rivers and oceans | Feb 2013 | 179898 | |
Protecting forests rivers and oceans | Mar 2013 | 281084 | |
Protecting forests rivers and oceans | Apr 2013 | 287900 | |
Protecting forests rivers and oceans | May 2013 | 297514 | |
Protecting forests rivers and oceans | Jun 2013 | 340946 | |
Protecting forests rivers and oceans | Jul 2013 | 290516 | |
Protecting forests rivers and oceans | Aug 2013 | 278620 | |
Protecting forests rivers and oceans | Sep 2013 | 308214 | |
Protecting forests rivers and oceans | Oct 2013 | 289317 | |
Protecting forests rivers and oceans | Nov 2013 | 302414 | |
Protecting forests rivers and oceans | Dec 2013 | 254676 | |
Protecting forests rivers and oceans | Jan 2014 | 290878 | |
Protecting forests rivers and oceans | Feb 2014 | 242703 | |
Protecting forests rivers and oceans | Mar 2014 | 350616 | |
Protecting forests rivers and oceans | Apr 2014 | 480955 | |
Protecting forests rivers and oceans | May 2014 | 453339 | |
Protection against crime and violence | Aug 2012 | 92270 | |
Protection against crime and violence | Sep 2012 | 92613 | |
Protection against crime and violence | Oct 2012 | 124658 | |
Protection against crime and violence | Nov 2012 | 202238 | |
Protection against crime and violence | Dec 2012 | 156750 | |
Protection against crime and violence | Jan 2013 | 176198 | |
Protection against crime and violence | Feb 2013 | 167719 | |
Protection against crime and violence | Mar 2013 | 227273 | |
Protection against crime and violence | Apr 2013 | 147938 | |
Protection against crime and violence | May 2013 | 160368 | |
Protection against crime and violence | Jun 2013 | 149503 | |
Protection against crime and violence | Jul 2013 | 175602 | |
Protection against crime and violence | Aug 2013 | 140459 | |
Protection against crime and violence | Sep 2013 | 129516 | |
Protection against crime and violence | Oct 2013 | 136174 | |
Protection against crime and violence | Nov 2013 | 344213 | |
Protection against crime and violence | Dec 2013 | 138267 | |
Protection against crime and violence | Jan 2014 | 135317 | |
Protection against crime and violence | Feb 2014 | 120099 | |
Protection against crime and violence | Mar 2014 | 201715 | |
Protection against crime and violence | Apr 2014 | 211106 | |
Protection against crime and violence | May 2014 | 265062 | |
Reliable energy at home | Aug 2012 | 132966 | |
Reliable energy at home | Sep 2012 | 113400 | |
Reliable energy at home | Oct 2012 | 208458 | |
Reliable energy at home | Nov 2012 | 146662 | |
Reliable energy at home | Dec 2012 | 127726 | |
Reliable energy at home | Jan 2013 | 143388 | |
Reliable energy at home | Feb 2013 | 361959 | |
Reliable energy at home | Mar 2013 | 159417 | |
Reliable energy at home | Apr 2013 | 164544 | |
Reliable energy at home | May 2013 | 153596 | |
Reliable energy at home | Jun 2013 | 175287 | |
Reliable energy at home | Jul 2013 | 173604 | |
Reliable energy at home | Aug 2013 | 147437 | |
Reliable energy at home | Sep 2013 | 162802 | |
Reliable energy at home | Oct 2013 | 170846 | |
Reliable energy at home | Nov 2013 | 174603 | |
Reliable energy at home | Dec 2013 | 194430 | |
Reliable energy at home | Jan 2014 | 192079 | |
Reliable energy at home | Feb 2014 | 153334 | |
Reliable energy at home | Mar 2014 | 195159 | |
Reliable energy at home | Apr 2014 | 257616 | |
Reliable energy at home | May 2014 | 253338 | |
Support for people who can't work | Aug 2012 | 51590 | |
Support for people who can't work | Sep 2012 | 53555 | |
Support for people who can't work | Oct 2012 | 107810 | |
Support for people who can't work | Nov 2012 | 73325 | |
Support for people who can't work | Dec 2012 | 70762 | |
Support for people who can't work | Jan 2013 | 62001 | |
Support for people who can't work | Feb 2013 | 39041 | |
Support for people who can't work | Mar 2013 | 67081 | |
Support for people who can't work | Apr 2013 | 90054 | |
Support for people who can't work | May 2013 | 93472 | |
Support for people who can't work | Jun 2013 | 58397 | |
Support for people who can't work | Jul 2013 | 56516 | |
Support for people who can't work | Aug 2013 | 45258 | |
Support for people who can't work | Sep 2013 | 56271 | |
Support for people who can't work | Oct 2013 | 72115 | |
Support for people who can't work | Nov 2013 | 80395 | |
Support for people who can't work | Dec 2013 | 106045 | |
Support for people who can't work | Jan 2014 | 129805 | |
Support for people who can't work | Feb 2014 | 64433 | |
Support for people who can't work | Mar 2014 | 67842 | |
Support for people who can't work | Apr 2014 | 92761 | |
Support for people who can't work | May 2014 | 88624 |