Built with blockbuilder.org
Last active
January 31, 2017 23:41
-
-
Save ohdebby/ae3a7fdd03493e2ea1f8b871a6df3a7f to your computer and use it in GitHub Desktop.
Mortality 1933-2014
This file contains 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
license: mit |
This file contains 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> | |
<meta charset="utf-8"> | |
<style type="text/css"> | |
body { | |
font-family: sans-serif; | |
} | |
text { | |
font-size: 12px; | |
fill: #888; | |
} | |
path, line { | |
stroke: #888; | |
stroke-width: 2; | |
fill: none; | |
} | |
</style> | |
<p>All-cause mortality, ages 50-54</p> | |
<svg width="700" height="500"></svg> | |
<script src="//d3js.org/d3.v4.min.js"></script> | |
<script> | |
var svg = d3.select("svg"), | |
margin = {top: 20, right: 80, bottom: 30, left: 50}, | |
width = svg.attr("width") - margin.left - margin.right, | |
height = svg.attr("height") - margin.top - margin.bottom, | |
g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
var parseTime = d3.timeParse("%Y"); | |
var x = d3.scaleTime().range([0, width]), | |
y = d3.scaleLinear().range([height, 0]), | |
z = d3.scaleOrdinal(d3.schemeCategory10); | |
var line = d3.line() | |
.defined(function (d) { return d[1] !==NaN; }) | |
// .curve(d3.curveBasis) | |
.x(function(d) { return x(d.year); }) | |
.y(function(d) { return y(d.mortality); }); | |
d3.csv("mortality1933-2014.csv", type, function(error, data) { | |
if (error) throw error; | |
var country = data.columns.slice(1).map(function(id) { | |
return { | |
id: id, | |
values: data.map(function(d) { | |
return {year: d.year, mortality: d[id]}; | |
}) | |
}; | |
}); | |
x.domain(d3.extent(data, function(d) { return d.year; })); | |
y.domain([0, | |
d3.max(country, function(c) { return d3.max(c.values, function(d) { return d.mortality; }); }) | |
]); | |
z.domain(country.map(function(c) { return c.id; })); | |
g.append("g") | |
.attr("class", "axis axis--x") | |
.attr("transform", "translate(0," + height + ")") | |
.call(d3.axisBottom(x)); | |
g.append("g") | |
.attr("class", "axis axis--y") | |
.call(d3.axisLeft(y)) | |
.append("text") | |
.attr("transform", "rotate(-90)") | |
.attr("y", -42) | |
.attr("x", -150) | |
.text("deaths per 100,000"); | |
var group = g.selectAll(".group") | |
.data(country) | |
.enter().append("g") | |
.attr("class", "group"); | |
group.append("path") | |
.attr("class", "line") | |
.attr("d", function(d) { return line(d.values); }) | |
.style("stroke", function(d) { return z(d.id); }); | |
group.append("text") | |
.datum(function(d) { return {id: d.id, value: d.values[d.values.length - 1]}; }) | |
.attr("transform", function(d) { return "translate(" + x(d.value.year) + "," + y(d.value.mortality) + ")"; }) | |
.attr("x", 3) | |
.attr("dy", "0.35em") | |
.style("font", "10px sans-serif") | |
.text(function(d) { return d.id; }); | |
}); | |
function type(d, _, columns) { | |
d.year = parseTime(d.year); | |
for (var i = 1, n = columns.length, c; i < n; ++i) d[c = columns[i]] = +d[c]; | |
return d; | |
} | |
</script> |
This file contains 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
year | US | UK | Sweden | France | Canada | Australia | |
---|---|---|---|---|---|---|---|
1933 | 1354.2 | 1169.4 | 896.2 | 1373.3 | 967.7 | 1007.2 | |
1934 | 1409.9 | 1107.9 | 886.5 | 1350.6 | 949.4 | 1006 | |
1935 | 1380.5 | 1092.6 | 872.8 | 1411.2 | 950.8 | 1030.2 | |
1936 | 1441.6 | 1128.6 | 943.8 | 1375.3 | 972.2 | 1016.1 | |
1937 | 1408 | 1141.4 | 926.6 | 1345 | 987.3 | 978.5 | |
1938 | 1306.9 | 1047.6 | 894.7 | 1368 | 941.8 | 992.3 | |
1939 | 1287 | 1066.4 | 877.8 | 1330.5 | 956.7 | 1000.6 | |
1940 | 1278.5 | 1228.8 | 856.9 | 1536.8 | 963.5 | 991.7 | |
1941 | 1240.8 | 1097.7 | 823.3 | 1477.8 | 943.5 | 971.9 | |
1942 | 1225.7 | 955.3 | 754.7 | 1312.4 | 948 | 1018.3 | |
1943 | 1250.6 | 989.5 | 736.8 | 1250.7 | 923.9 | 984 | |
1944 | 1193.4 | 945.1 | 754.3 | 1547.6 | 910.8 | 889.1 | |
1945 | 1169.1 | 921.1 | 756 | 1149.1 | 890 | 899.2 | |
1946 | 1131.8 | 900.8 | 700.7 | 931.7 | 868.5 | 941.6 | |
1947 | 1139 | 911.7 | 751.4 | 921.5 | 870 | 956.6 | |
1948 | 1110.3 | 843.5 | 705.2 | 929.9 | 881.9 | 932.3 | |
1949 | 1056.4 | 860.2 | 702 | 975.1 | 859.2 | 869.1 | |
1950 | 1042.2 | 854 | 660.5 | 974.2 | 837.7 | 887.5 | |
1951 | 1057.7 | 891 | 642.2 | 1010.1 | 841.8 | 916 | |
1952 | 1037.5 | 820.6 | 641.2 | 962.8 | 856.6 | 906.3 | |
1953 | 1022.1 | 804.9 | 609.2 | 995.5 | 844.5 | 870.5 | |
1954 | 974.9 | 806.2 | 589.5 | 945.6 | 806.1 | 859.2 | |
1955 | 946.7 | 798.8 | 593.9 | 930.7 | 774.5 | 815.6 | |
1956 | 925.1 | 766.9 | 576.3 | 951 | 767.2 | 804.4 | |
1957 | 958.9 | 779.5 | 585.6 | 916 | 773.6 | 787.6 | |
1958 | 946 | 768.6 | 546.6 | 822.3 | 767.9 | 798.9 | |
1959 | 927.8 | 751.8 | 532.6 | 827.8 | 759.1 | 785.7 | |
1960 | 937.9 | 742.6 | 539.5 | 840.3 | 737.4 | 782.5 | |
1961 | 912.4 | 751.7 | 545.9 | 791.5 | 749.1 | 775 | |
1962 | 924.8 | 743.7 | 540.6 | 814.9 | 730.7 | 797.7 | |
1963 | 931.4 | 752.1 | 516.4 | 817.2 | 732.8 | 796.2 | |
1964 | 924.1 | 733 | 536.7 | 782.4 | 733.3 | 818.7 | |
1965 | 924.5 | 739.9 | 547.6 | 798.7 | 751.6 | 833.6 | |
1966 | 924.6 | 749.9 | 528.7 | 779.6 | 736.6 | 820.9 | |
1967 | 905.4 | 714.4 | 527.7 | 785.9 | 729.2 | 805.5 | |
1968 | 920.6 | 739.9 | 519.8 | 781.1 | 708.7 | 823.5 | |
1969 | 892.1 | 747.3 | 527.8 | 780.8 | 712.2 | 800.9 | |
1970 | 884.8 | 733.4 | 536.6 | 722 | 705.1 | 815.3 | |
1971 | 860.8 | 717.7 | 530.7 | 736.7 | 682.8 | 756.9 | |
1972 | 852.7 | 741.6 | 536.2 | 733.1 | 686.9 | 748.7 | |
1973 | 834.6 | 729.1 | 528.4 | 719.5 | 686.3 | 726.2 | |
1974 | 810.1 | 749.8 | 546.1 | 739.1 | 688.6 | 768.6 | |
1975 | 785.5 | 721.1 | 536.3 | 742.6 | 670.3 | 724.7 | |
1976 | 770.3 | 727.2 | 538 | 744 | 660 | 709.5 | |
1977 | 754.8 | 702.9 | 539.5 | 710.1 | 659.1 | 674.3 | |
1978 | 744.1 | 714.1 | 525.6 | 701.5 | 656.9 | 650.2 | |
1979 | 719.9 | 707.1 | 544.7 | 712.7 | 636.4 | 636.1 | |
1980 | 713.9 | 668.6 | 517 | 704.6 | 607.1 | 616.9 | |
1981 | 696.6 | 648 | 499.1 | 692.6 | 584.9 | 589.2 | |
1982 | 672.8 | 626.9 | 482.5 | 681 | 572 | 587.8 | |
1983 | 666.6 | 603.2 | 496.2 | 677 | 550.8 | 565.4 | |
1984 | 651.4 | 584.9 | 459.1 | 652 | 529.3 | 536.3 | |
1985 | 646.7 | 576.5 | 464.9 | 645.7 | 528.6 | 518.9 | |
1986 | 635.1 | 555.3 | 450.9 | 632.5 | 523.4 | 487.8 | |
1987 | 629.3 | 538.8 | 461.2 | 603 | 496.1 | 485.4 | |
1988 | 614.2 | 522.2 | 435.6 | 583.8 | 470.2 | 466.2 | |
1989 | 600.2 | 504.8 | 416.2 | 572.3 | 461.8 | 453.2 | |
1990 | 585 | 496.3 | 395.2 | 548.8 | 455.3 | 428.9 | |
1991 | 572.8 | 488.3 | 395 | 528.9 | 435.3 | 414.8 | |
1992 | 561 | 471.2 | 394.8 | 522 | 430.6 | 410.6 | |
1993 | 565 | 475.3 | 386 | 510.7 | 422.6 | 379.1 | |
1994 | 562.6 | 449 | 379.6 | 512.3 | 415.8 | 376.7 | |
1995 | 558.5 | 450.2 | 376.7 | 496.8 | 417.5 | 365.9 | |
1996 | 533.8 | 435.2 | 376.9 | 499.3 | 400.2 | 360.2 | |
1997 | 519.1 | 426.9 | 365.6 | 488.3 | 382.3 | 351.8 | |
1998 | 500.9 | 419.9 | 346.4 | 482.3 | 373.3 | 335.8 | |
1999 | 501.4 | 415 | 339.3 | 480.5 | 367 | 313.5 | |
2000 | 503.6 | 406.6 | 339.1 | 472.8 | 366.1 | 313.6 | |
2001 | 511 | 405.3 | 338.8 | 470.4 | 361.9 | 305.9 | |
2002 | 512.1 | 396.2 | 320.3 | 476.6 | 352.6 | 305.9 | |
2003 | 515.6 | 394.5 | 317.2 | 481.3 | 359.8 | 280.3 | |
2004 | 509.8 | 385.1 | 314.2 | 458.8 | 348.8 | 289.5 | |
2005 | 518.8 | 377.2 | 315.2 | 455.8 | 343.1 | 285.5 | |
2006 | 513.7 | 378.7 | 310.1 | 457.7 | 342.3 | 282.6 | |
2007 | 506.3 | 367.3 | 298.1 | 443.5 | 341.4 | 292.2 | |
2008 | 505.1 | 365.3 | 296 | 437.4 | 342 | 284.8 | |
2009 | 505.4 | 346 | 294.4 | 433.5 | 334.5 | 290.2 | |
2010 | 491.2 | 342.9 | 268.7 | 424.8 | 320.6 | 277 | |
2011 | 495.3 | 329.2 | 261 | 413.2 | 308 | 275.7 | |
2012 | 491.3 | 316.1 | 263.7 | 399 | |||
2013 | 491.1 | 316.6 | 261.5 | 382.3 | |||
2014 | 493.3 | 246.7 | 364.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment