Last active
October 16, 2016 22:01
-
-
Save pstuffa/c65d82662507d677249db3d1513b874f to your computer and use it in GitHub Desktop.
Barley Network
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> | |
.nodes circle { | |
fill: #ccc; | |
stroke: #000; | |
} | |
.links { | |
stroke: #999; | |
stroke-width: 1.5px; | |
} | |
.text { | |
pointer-events: none; | |
text-anchor: middle; | |
font: 10px sans-serif; | |
} | |
</style> | |
<svg width="960" height="600"></svg> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script> | |
var svg = d3.select("svg"), | |
width = +svg.attr("width"), | |
height = +svg.attr("height"); | |
var simulation = d3.forceSimulation() | |
.force("charge", d3.forceManyBody().strength(-50)) | |
.force("link", d3.forceLink().id(function(d) { return d.id; })) | |
.force("x", d3.forceX(width / 2)) | |
.force("y", d3.forceY(height / 2)); | |
var color = d3.scaleOrdinal(d3.schemeCategory20c); | |
d3.tsv("barley.tsv", function(error, data) { | |
var yieldLookup = {} | |
data.forEach(function(d) { | |
d.site = d.site.replace(" ","").replace(". ", "") | |
d.variety = d.variety.replace(" ","").replace(". ", "") | |
yieldLookup[d.site + '-' + d.variety + "-" + d.year] = +d.yield; | |
}) | |
var sites = d3.set(data.map(function(d) { return d.site; })).values(); | |
var siteVarieties = d3.set(data.map(function(d) { return d.site + '-' + d.variety; })).values(); | |
var siteVarietiesYears = d3.set(data.map(function(d) { return d.site + '-' + d.variety + "-" + d.year; })).values(); | |
var nodes = [], | |
links = []; | |
sites.forEach(function(site){ | |
nodes.push({"id" : site, | |
"shortName": site, | |
"radius": 10, | |
"color": "#fff", | |
"classValue": "site" }) | |
}); | |
siteVarieties.forEach(function(siteVariety) { | |
nodes.push({"id" : siteVariety, | |
"shortName": siteVariety.split("-")[1], | |
"radius": 10, | |
"color" : color(siteVariety.split("-")[1]), | |
"classValue": siteVariety.split("-")[1].replace(".","") }); | |
links.push({ | |
"source": siteVariety.split("-")[0], | |
"target": siteVariety | |
}) | |
}); | |
siteVarietiesYears.forEach(function(svy) { | |
nodes.push({"id" : svy, | |
"shortName": svy.split("-")[2], | |
"radius": Math.sqrt(yieldLookup[svy])/Math.PI*10, | |
"color": color(svy.split("-")[1]), | |
"classValue": svy.split("-")[1].replace(".","") }); | |
links.push({ | |
"source": svy.split("-")[0] + '-' + svy.split("-")[1], | |
"target": svy | |
}) | |
}); | |
var graph = { | |
"nodes": nodes, | |
"links": links | |
} | |
var link = svg.append("g") | |
.attr("class", "links") | |
.selectAll("line") | |
.data(graph.links) | |
.enter().append("line"); | |
var node = svg.append("g") | |
.attr("class", "nodes") | |
.selectAll("circle") | |
.data(graph.nodes) | |
.enter().append("circle") | |
.attr("class", function(d) { return d.classValue; }) | |
.attr("r", function(d) { return d.radius; }) | |
.style("fill", function(d) { return d.color; }) | |
.call(d3.drag() | |
.on("start", dragstarted) | |
.on("drag", dragged) | |
.on("end", dragended)); | |
var text = svg.append("g") | |
.attr("class", "text") | |
.selectAll("text") | |
.data(graph.nodes) | |
.enter().append("text") | |
.text(function(d, i) { return d.shortName; }) | |
simulation | |
.nodes(graph.nodes) | |
.on("tick", ticked); | |
simulation.force("link") | |
.links(graph.links); | |
function ticked() { | |
link.attr("x1", function(d) { return d.source.x; }) | |
.attr("y1", function(d) { return d.source.y; }) | |
.attr("x2", function(d) { return d.target.x; }) | |
.attr("y2", function(d) { return d.target.y; }); | |
node.attr("cx", function(d) { return d.x; }) | |
.attr("cy", function(d) { return d.y; }); | |
text.attr("x", function(d) { return d.x; }) | |
.attr("y", function(d) { return d.y; }); | |
} | |
}); | |
function dragstarted(d) { | |
if (!d3.event.active) simulation.alphaTarget(0.3).restart(); | |
d.fx = d.x; | |
d.fy = d.y; | |
} | |
function dragged(d) { | |
d.fx = d3.event.x; | |
d.fy = d3.event.y; | |
} | |
function dragended(d) { | |
if (!d3.event.active) simulation.alphaTarget(0); | |
d.fx = null; | |
d.fy = null; | |
} | |
</script> | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment