Last active
August 29, 2015 14:24
-
-
Save kcsluis/4652ed93fea6095540d9 to your computer and use it in GitHub Desktop.
Barley
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
yield | variety | year | site | |
---|---|---|---|---|
27 | Manchuria | 1931 | University Farm | |
48.86667 | Manchuria | 1931 | Waseca | |
27.43334 | Manchuria | 1931 | Morris | |
39.93333 | Manchuria | 1931 | Crookston | |
32.96667 | Manchuria | 1931 | Grand Rapids | |
28.96667 | Manchuria | 1931 | Duluth | |
43.06666 | Glabron | 1931 | University Farm | |
55.2 | Glabron | 1931 | Waseca | |
28.76667 | Glabron | 1931 | Morris | |
38.13333 | Glabron | 1931 | Crookston | |
29.13333 | Glabron | 1931 | Grand Rapids | |
29.66667 | Glabron | 1931 | Duluth | |
35.13333 | Svansota | 1931 | University Farm | |
47.33333 | Svansota | 1931 | Waseca | |
25.76667 | Svansota | 1931 | Morris | |
40.46667 | Svansota | 1931 | Crookston | |
29.66667 | Svansota | 1931 | Grand Rapids | |
25.7 | Svansota | 1931 | Duluth | |
39.9 | Velvet | 1931 | University Farm | |
50.23333 | Velvet | 1931 | Waseca | |
26.13333 | Velvet | 1931 | Morris | |
41.33333 | Velvet | 1931 | Crookston | |
23.03333 | Velvet | 1931 | Grand Rapids | |
26.3 | Velvet | 1931 | Duluth | |
36.56666 | Trebi | 1931 | University Farm | |
63.8333 | Trebi | 1931 | Waseca | |
43.76667 | Trebi | 1931 | Morris | |
46.93333 | Trebi | 1931 | Crookston | |
29.76667 | Trebi | 1931 | Grand Rapids | |
33.93333 | Trebi | 1931 | Duluth | |
43.26667 | No. 457 | 1931 | University Farm | |
58.1 | No. 457 | 1931 | Waseca | |
28.7 | No. 457 | 1931 | Morris | |
45.66667 | No. 457 | 1931 | Crookston | |
32.16667 | No. 457 | 1931 | Grand Rapids | |
33.6 | No. 457 | 1931 | Duluth | |
36.6 | No. 462 | 1931 | University Farm | |
65.7667 | No. 462 | 1931 | Waseca | |
30.36667 | No. 462 | 1931 | Morris | |
48.56666 | No. 462 | 1931 | Crookston | |
24.93334 | No. 462 | 1931 | Grand Rapids | |
28.1 | No. 462 | 1931 | Duluth | |
32.76667 | Peatland | 1931 | University Farm | |
48.56666 | Peatland | 1931 | Waseca | |
29.86667 | Peatland | 1931 | Morris | |
41.6 | Peatland | 1931 | Crookston | |
34.7 | Peatland | 1931 | Grand Rapids | |
32 | Peatland | 1931 | Duluth | |
24.66667 | No. 475 | 1931 | University Farm | |
46.76667 | No. 475 | 1931 | Waseca | |
22.6 | No. 475 | 1931 | Morris | |
44.1 | No. 475 | 1931 | Crookston | |
19.7 | No. 475 | 1931 | Grand Rapids | |
33.06666 | No. 475 | 1931 | Duluth | |
39.3 | Wisconsin No. 38 | 1931 | University Farm | |
58.8 | Wisconsin No. 38 | 1931 | Waseca | |
29.46667 | Wisconsin No. 38 | 1931 | Morris | |
49.86667 | Wisconsin No. 38 | 1931 | Crookston | |
34.46667 | Wisconsin No. 38 | 1931 | Grand Rapids | |
31.6 | Wisconsin No. 38 | 1931 | Duluth | |
26.9 | Manchuria | 1932 | University Farm | |
33.46667 | Manchuria | 1932 | Waseca | |
34.36666 | Manchuria | 1932 | Morris | |
32.96667 | Manchuria | 1932 | Crookston | |
22.13333 | Manchuria | 1932 | Grand Rapids | |
22.56667 | Manchuria | 1932 | Duluth | |
36.8 | Glabron | 1932 | University Farm | |
37.73333 | Glabron | 1932 | Waseca | |
35.13333 | Glabron | 1932 | Morris | |
26.16667 | Glabron | 1932 | Crookston | |
14.43333 | Glabron | 1932 | Grand Rapids | |
25.86667 | Glabron | 1932 | Duluth | |
27.43334 | Svansota | 1932 | University Farm | |
38.5 | Svansota | 1932 | Waseca | |
35.03333 | Svansota | 1932 | Morris | |
20.63333 | Svansota | 1932 | Crookston | |
16.63333 | Svansota | 1932 | Grand Rapids | |
22.23333 | Svansota | 1932 | Duluth | |
26.8 | Velvet | 1932 | University Farm | |
37.4 | Velvet | 1932 | Waseca | |
38.83333 | Velvet | 1932 | Morris | |
32.06666 | Velvet | 1932 | Crookston | |
32.23333 | Velvet | 1932 | Grand Rapids | |
22.46667 | Velvet | 1932 | Duluth | |
29.06667 | Trebi | 1932 | University Farm | |
49.2333 | Trebi | 1932 | Waseca | |
46.63333 | Trebi | 1932 | Morris | |
41.83333 | Trebi | 1932 | Crookston | |
20.63333 | Trebi | 1932 | Grand Rapids | |
30.6 | Trebi | 1932 | Duluth | |
26.43334 | No. 457 | 1932 | University Farm | |
42.2 | No. 457 | 1932 | Waseca | |
43.53334 | No. 457 | 1932 | Morris | |
34.33333 | No. 457 | 1932 | Crookston | |
19.46667 | No. 457 | 1932 | Grand Rapids | |
22.7 | No. 457 | 1932 | Duluth | |
25.56667 | No. 462 | 1932 | University Farm | |
44.7 | No. 462 | 1932 | Waseca | |
47 | No. 462 | 1932 | Morris | |
30.53333 | No. 462 | 1932 | Crookston | |
19.9 | No. 462 | 1932 | Grand Rapids | |
22.5 | No. 462 | 1932 | Duluth | |
28.06667 | Peatland | 1932 | University Farm | |
36.03333 | Peatland | 1932 | Waseca | |
43.2 | Peatland | 1932 | Morris | |
25.23333 | Peatland | 1932 | Crookston | |
26.76667 | Peatland | 1932 | Grand Rapids | |
31.36667 | Peatland | 1932 | Duluth | |
30 | No. 475 | 1932 | University Farm | |
41.26667 | No. 475 | 1932 | Waseca | |
44.23333 | No. 475 | 1932 | Morris | |
32.13333 | No. 475 | 1932 | Crookston | |
15.23333 | No. 475 | 1932 | Grand Rapids | |
27.36667 | No. 475 | 1932 | Duluth | |
38 | Wisconsin No. 38 | 1932 | University Farm | |
58.16667 | Wisconsin No. 38 | 1932 | Waseca | |
47.16667 | Wisconsin No. 38 | 1932 | Morris | |
35.9 | Wisconsin No. 38 | 1932 | Crookston | |
20.66667 | Wisconsin No. 38 | 1932 | Grand Rapids | |
29.33333 | Wisconsin No. 38 | 1932 | Duluth |
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"> | |
/* svg { | |
border: 1px solid #f0f; | |
}*/ | |
body { | |
font-family: 'arial', sans-serif; | |
font-size: 9px; | |
width: 960px; | |
margin: 40px auto; | |
} | |
h1 { | |
font-size: 36px; | |
} | |
h3 { | |
margin-bottom: 0px; | |
} | |
.g-site { | |
display: inline-block; | |
margin-right: 20px; | |
} | |
.axis path { | |
display: none; | |
} | |
.year-1931 { | |
fill: red; | |
} | |
.year-1932 { | |
fill: blue; | |
} | |
</style> | |
<body> | |
<h1>Barley</h1> | |
</body> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js" charset="utf-8"></script> | |
<script> | |
var marginCore = 20; | |
var margin = {top: 20, right: marginCore, bottom: 20, left: 100}; | |
var width = 300 - margin.left - margin.right, | |
height = 150 - margin.top - margin.bottom; | |
d3.tsv("barley.tsv", function(error, data) { | |
if (error) throw error; | |
// format your data | |
data.forEach( function (d) { | |
d.yield = +d.yield; | |
d.year = +d.year; | |
}); | |
// use map to strip out jobs_change | |
var morrisData = data.filter( function (d) { return d.site == "Morris"; }); | |
// console.log(morrisData); | |
var allVarieties = data.map( function (d) { return d.variety; }); | |
var morrisVarieties = d3.set(allVarieties).values(); | |
// console.log(morrisVarieties); | |
var morrisYields = morrisData.map( function (d) { return d.yield; }); | |
// console.log(morrisYields); | |
var morrisMax = d3.max(morrisYields); | |
// console.log(morrisMax); | |
morrisData.sort( function (a,b) { return b.yield - a.yield; }); | |
var dataYields = data.map( function (d) { return d.yield; }); | |
var dataMax = d3.max(dataYields); | |
console.log(dataMax); | |
// x and y scale domain and range | |
var xScale = d3.scale.linear() | |
.range([0,width]) | |
.domain([0, dataMax]); | |
var yScale = d3.scale.ordinal() | |
.rangeBands([height, 0], 0.333) | |
.domain(morrisVarieties); | |
var yieldsBySite = d3.nest() | |
.key( function (d) { return d.site; }) | |
// .rollup - use this to add additional nodes with which to sort | |
// assign node another value to use to sort | |
// really important to have entries | |
.entries(data); | |
yieldsBySite | |
console.log(yieldsBySite); | |
var site = d3.select('body').selectAll('.g-site') | |
.data(yieldsBySite) | |
.enter() | |
.append('div') | |
.attr('class', function (d) { return d.key + ' g-site'; }); | |
site.append('h3').text( function (d) { return d.key; }); | |
var svg = site.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 + ")"); | |
var xAxis = d3.svg.axis() | |
.scale(xScale) | |
.tickSize(3) | |
.tickPadding(0) | |
.orient("top"); | |
var yAxis = d3.svg.axis() | |
.scale(yScale) | |
.tickSize(3) | |
.tickPadding(6) | |
.orient("left"); | |
// var varietyGroup = svg.selectAll(".variety-group") | |
// .data(morrisData) | |
// .enter() | |
// .append("g") | |
// .attr("class", "variety-group") | |
// .attr('transform', function (d) { return 'translate(0,' + yScale(d.variety) + ')'; }) | |
// // kind of weird, but because it's only morrisData, you only want for each variety | |
// // I was really thrown when I .data(data) instead of .data(morrisData) | |
// ; | |
// // varietyGroup.append('circle') | |
// // .attr('r', 5) | |
// // .attr('cx', function (d) { return xScale(d.yield); }); | |
// varietyGroup.append('rect') | |
// .attr('fill-opacity', 0.5) | |
// .attr('class', function (d) { return 'year-' + d.year; }) | |
// .attr('x', xScale(0)) | |
// .attr('width', function (d) { return xScale(d.yield); }) | |
// .attr('height', yScale.rangeBand()); | |
svg.append("g") | |
.attr("class", "axis xAxis") | |
.call(xAxis); | |
svg.append("g") | |
.attr("class", "axis yAxis") | |
.call(yAxis); | |
var varietyGroup = svg.selectAll(".variety-group") | |
.data( function (d) { return d.values; }) | |
// it's a data join in a data join | |
// data join inception | |
.enter() | |
.append("g") | |
.attr("class", "variety-group") | |
.attr('transform', function (d) { return 'translate(0,' + yScale(d.variety) + ')'; }) | |
; | |
// varietyGroup.append('circle') | |
// .attr('r', 5) | |
// .attr('cx', function (d) { return xScale(d.yield); }); | |
varietyGroup.append('rect') | |
.attr('fill-opacity', 0.5) | |
.attr('class', function (d) { return 'year-' + d.year; }) | |
.attr('x', xScale(0)) | |
.attr('width', function (d) { return xScale(d.yield); }) | |
.attr('height', yScale.rangeBand()); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment