Skip to content

Instantly share code, notes, and snippets.

@emagee
Created July 31, 2015 18:26
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 emagee/1846f73fe4ca941c6662 to your computer and use it in GitHub Desktop.
Save emagee/1846f73fe4ca941c6662 to your computer and use it in GitHub Desktop.
More small multiples, repeated axes
subject date count
Agriculture 2002 1418
Agriculture 2003 1535
Agriculture 2004 1501
Agriculture 2005 1483
Agriculture 2006 1426
Agriculture 2007 1259
Agriculture 2008 1556
Agriculture 2009 1363
Agriculture 2010 1833
Agriculture 2011 1773
Agriculture 2012 2194
Agriculture 2013 1470
Arts 2002 6574
Arts 2003 8431
Arts 2004 8779
Arts 2005 8762
Arts 2006 9201
Arts 2007 9291
Arts 2008 10304
Arts 2009 9860
Arts 2010 10910
Arts 2011 10701
Arts 2012 11320
Arts 2013 11083
Biography 2002 6873
Biography 2003 9837
Biography 2004 9765
Biography 2005 8904
Biography 2006 11271
Biography 2007 11414
Biography 2008 11375
Biography 2009 13795
Biography 2010 12291
Biography 2011 12163
Biography 2012 11333
Biography 2013 10842
Business 2002 6918
Business 2003 7614
Business 2004 7905
Business 2005 7885
Business 2006 8719
Business 2007 7722
Business 2008 8873
Business 2009 9351
Business 2010 10194
Business 2011 10109
Business 2012 13989
Business 2013 11116
Computers 2002 7564
Computers 2003 8955
Computers 2004 6928
Computers 2005 6092
Computers 2006 5472
Computers 2007 6069
Computers 2008 5638
Computers 2009 5276
Computers 2010 7553
Computers 2011 6986
Computers 2012 7028
Computers 2013 6959
Cooking 2002 1956
Cooking 2003 2590
Cooking 2004 2857
Cooking 2005 3062
Cooking 2006 2705
Cooking 2007 2836
Cooking 2008 3164
Cooking 2009 2643
Cooking 2010 3057
Cooking 2011 2963
Cooking 2012 3168
Cooking 2013 3181
Education 2002 6829
Education 2003 7562
Education 2004 7135
Education 2005 6951
Education 2006 6449
Education 2007 7162
Education 2008 9640
Education 2009 9578
Education 2010 10839
Education 2011 11820
Education 2012 11122
Education 2013 10669
General Works 2002 2085
General Works 2003 2195
General Works 2004 4266
General Works 2005 2017
General Works 2006 2078
General Works 2007 2211
General Works 2008 2400
General Works 2009 2562
General Works 2010 3004
General Works 2011 2708
General Works 2012 2507
General Works 2013 2446
History 2002 11362
History 2003 13192
History 2004 14191
History 2005 12686
History 2006 15241
History 2007 14406
History 2008 13477
History 2009 15480
History 2010 14659
History 2011 12270
History 2012 11959
History 2013 12471
Home Economics 2002 1434
Home Economics 2003 1628
Home Economics 2004 1760
Home Economics 2005 1634
Home Economics 2006 1755
Home Economics 2007 1775
Home Economics 2008 1644
Home Economics 2009 1656
Home Economics 2010 1699
Home Economics 2011 1579
Home Economics 2012 1664
Home Economics 2013 1508
Language 2002 5924
Language 2003 6899
Language 2004 6088
Language 2005 5669
Language 2006 5134
Language 2007 4879
Language 2008 6181
Language 2009 5426
Language 2010 4929
Language 2011 4358
Language 2012 4537
Language 2013 4475
Law 2002 4432
Law 2003 4675
Law 2004 4509
Law 2005 5468
Law 2006 5359
Law 2007 5195
Law 2008 5533
Law 2009 5915
Law 2010 5908
Law 2011 5795
Law 2012 5531
Law 2013 6072
Literature 2002 6261
Literature 2003 6493
Literature 2004 7972
Literature 2005 6297
Literature 2006 8227
Literature 2007 9974
Literature 2008 10843
Literature 2009 11456
Literature 2010 9315
Literature 2011 7054
Literature 2012 7004
Literature 2013 8591
Medicine 2002 9495
Medicine 2003 10522
Medicine 2004 11834
Medicine 2005 11688
Medicine 2006 10931
Medicine 2007 10777
Medicine 2008 11022
Medicine 2009 11093
Medicine 2010 12869
Medicine 2011 13690
Medicine 2012 15077
Medicine 2013 13400
Music 2002 3376
Music 2003 3740
Music 2004 4859
Music 2005 4076
Music 2006 3545
Music 2007 3540
Music 2008 4131
Music 2009 4570
Music 2010 3927
Music 2011 3948
Music 2012 4273
Music 2013 5294
Personal Finance 2002 473
Personal Finance 2003 402
Personal Finance 2004 552
Personal Finance 2005 542
Personal Finance 2006 582
Personal Finance 2007 582
Personal Finance 2008 598
Personal Finance 2009 699
Personal Finance 2010 595
Personal Finance 2011 636
Personal Finance 2012 591
Personal Finance 2013 538
Philosophy & Psychology 2002 8894
Philosophy & Psychology 2003 10040
Philosophy & Psychology 2004 11410
Philosophy & Psychology 2005 10556
Philosophy & Psychology 2006 12961
Philosophy & Psychology 2007 13098
Philosophy & Psychology 2008 12605
Philosophy & Psychology 2009 13949
Philosophy & Psychology 2010 14277
Philosophy & Psychology 2011 14011
Philosophy & Psychology 2012 15018
Philosophy & Psychology 2013 15479
Poetry & Drama 2002 5742
Poetry & Drama 2003 7007
Poetry & Drama 2004 9891
Poetry & Drama 2005 9414
Poetry & Drama 2006 10700
Poetry & Drama 2007 11610
Poetry & Drama 2008 11700
Poetry & Drama 2009 13474
Poetry & Drama 2010 11723
Poetry & Drama 2011 9653
Poetry & Drama 2012 10038
Poetry & Drama 2013 10156
Religion 2002 12253
Religion 2003 14517
Religion 2004 21669
Religion 2005 16785
Religion 2006 19854
Religion 2007 19540
Religion 2008 18296
Religion 2009 20527
Religion 2010 18937
Religion 2011 18518
Religion 2012 19854
Religion 2013 18653
Science 2002 11688
Science 2003 12962
Science 2004 12639
Science 2005 12626
Science 2006 12655
Science 2007 12714
Science 2008 14100
Science 2009 15608
Science 2010 20706
Science 2011 19010
Science 2012 18852
Science 2013 18684
Sociology & Economics 2002 20969
Sociology & Economics 2003 23530
Sociology & Economics 2004 23222
Sociology & Economics 2005 23750
Sociology & Economics 2006 27675
Sociology & Economics 2007 24546
Sociology & Economics 2008 24737
Sociology & Economics 2009 26904
Sociology & Economics 2010 28581
Sociology & Economics 2011 28356
Sociology & Economics 2012 28442
Sociology & Economics 2013 29399
Sports & Recreation 2002 5800
Sports & Recreation 2003 6323
Sports & Recreation 2004 6196
Sports & Recreation 2005 6438
Sports & Recreation 2006 6666
Sports & Recreation 2007 6362
Sports & Recreation 2008 6262
Sports & Recreation 2009 5971
Sports & Recreation 2010 6639
Sports & Recreation 2011 6198
Sports & Recreation 2012 6197
Sports & Recreation 2013 5807
Technology 2002 6896
Technology 2003 7142
Technology 2004 7753
Technology 2005 7138
Technology 2006 7262
Technology 2007 7131
Technology 2008 7666
Technology 2009 8688
Technology 2010 11599
Technology 2011 10131
Technology 2012 11564
Technology 2013 9769
Travel 2002 4316
Travel 2003 4172
Travel 2004 5304
Travel 2005 4941
Travel 2006 5376
Travel 2007 5678
Travel 2008 5101
Travel 2009 4800
Travel 2010 4572
Travel 2011 3755
Travel 2012 3603
Travel 2013 3450
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
margin: 0;
}
.line {
fill: none;
stroke: #426789;
stroke-width: 5px;
}
.area {
fill: #e8eef4;
}
g#xAxisG text, g#yAxisG text {
stroke: none;
fill: silver;
font-size: 9px;
}
header, div#source {
margin-left: 40px;
margin-bottom: 38px;
}
header p {
font-size: 1.4em;
line-height: 1.25em;
}
div#source p {
font-size: 12px;
}
h1 {
color: #B35959;
margin-bottom: 6px;
font-size: 3em;
}
h2 {
color: #426789;
margin-top: 4px;
margin-bottom: 20px;
font-weight: normal;
font-size: 1.75em;
}
.small {
font-size: .85em;
}
</style>
<body>
<header>
<h1>ISBN counts for print adult nonfiction books, 2002&ndash;2012</h1>
<h2>By subject, as reported by Bowker customers when registering a book's ISBN</h2>
<p>According to Wikipedia, &ldquo;...Bowker provides bibliographic information on published works to the book trade, including publishers, booksellers, libraries, and individuals... Bowker is the exclusive U.S. agent for issuing International Standard Book Numbers (ISBNs), a universal method of identifying books in print.&rdquo; <span class="small">(<a href = "https://en.wikipedia.org/wiki/R.R._Bowker">https://en.wikipedia.org/wiki/R.R._Bowker</a>, accessed July 31, 2015)</span></p>
</header>
<div id="mainSVG"></div>
<div id="source">
<p>Source: <a href="http://www.bowker.com/documents/isbn-output-report-2002-2013.html">http://www.bowker.com/documents/isbn-output-report-2002-2013.html</a></p>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script>
var margin = {top: 8, right: 15, bottom: 20, left: 40},
width = 180 - margin.left - margin.right,
height = 120 - margin.top - margin.bottom;
var parseDate = d3.time.format("%Y").parse;
var x = d3.time.scale()
.range([10, width+10]);
var y = d3.scale.linear()
.range([height, 0]);
var area = d3.svg.area()
.x(function(d) { return x(d.date); })
.y0(height)
.y1(function(d) { return y(d.count); });
var line = d3.svg.line()
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.count); });
d3.csv("bowker-data-clean-reformatted-3.csv", type, function(error, data) {
// Nest data by subject.
var subjects = d3.nest()
.key(function(d) { return d.subject; })
.entries(data);
// Compute the maximum count per subject, needed for the y-domain.
subjects.forEach(function(s) {
s.maxCount = d3.max(s.values, function(d) { return d.count+500; });
});
// Compute the minimum and maximum date across subjects.
// We assume values are sorted by date.
x.domain([
d3.min(subjects, function(s) { return s.values[0].date; }),
d3.max(subjects, function(s) { return s.values[s.values.length - 1].date; })
]);
// Add an SVG element for each subject, with the desired dimensions and margin.
var svg = d3.select("#mainSVG").selectAll("svg")
.data(subjects)
.enter().append("svg")
.style("margin-bottom", "10px")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
;
// Add the area path elements. Note: the y-domain is set per element.
svg.append("path")
.attr("class", "area")
.attr("d", function(d) { y.domain([0, 33000]); return area(d.values); });
// Add the line path elements. Note: the y-domain is set per element.
svg.append("path")
.attr("class", "line")
.attr("d", function(d) { y.domain([0, 33000]); return line(d.values); });
// Add a small label for the symbol name.
svg.append("text")
.attr("x", (width + 10)/2)
.attr("y", height - 85)
.style("text-anchor", "middle")
.style("font-family", "helvetica, 'sans-serif'")
.style("font-size", "12px")
/*.style("font-weight", "bold")*/
.attr("fill", "#B35959")
.text(function(d) { return d.key; });
// attempt to add axes
var xScale = x;
var yScale = y;
var yAxis = d3.svg.axis().scale(yScale).orient("left")
.tickFormat(function (d) {
if ((d / 1000) >= 1) {
d = d / 1000 + "K";
}
return d;
});
svg.append("g").attr("id", "yAxisG").call(yAxis);
var xAxis = d3.svg.axis().scale(xScale).orient("bottom").ticks(3);
svg.append("g").attr("id", "xAxisG").call(xAxis);
d3.selectAll("path.domain").style("fill", "none").style("stroke", "silver");
d3.selectAll("line").style("stroke", "silver");
console.log(height);
d3.selectAll("#xAxisG").attr("transform","translate(0,92)");
});
function type(d) {
d.count = +d.count;
d.date = parseDate(d.date);
return d;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment