Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Collaboration networks among departments at MIT

An exploration of collaboration between departments and schools at MIT, assembled as part of the Datalore hackathon at the MIT Media Lab.

{
"nodes":[
{"name":"School of Architecture and Planning","group":1},
{"name":"Architecture","group":1},
{"name":"Media Arts and Sciences","group":1},
{"name":"Urban Studies and Planning","group":1},
{"name":"School of Engineering","group":2},
{"name":"Aeronautics and Astronautics","group":2},
{"name":"Biological Engineering","group":2},
{"name":"Chemical Engineering","group":2},
{"name":"Civil and Environmental Engineering","group":2}
],
"links":[
{"source":2,"target":0,"value":2},
{"source":2,"target":1,"value":4},
{"source":3,"target":0,"value":2},
{"source":3,"target":1,"value":2},
{"source":4,"target":2,"value":2},
{"source":4,"target":3,"value":2},
{"source":5,"target":2,"value":4},
{"source":5,"target":3,"value":6},
{"source":5,"target":4,"value":14},
{"source":6,"target":2,"value":46},
{"source":6,"target":3,"value":2},
{"source":6,"target":4,"value":26},
{"source":6,"target":5,"value":2},
{"source":7,"target":4,"value":14},
{"source":7,"target":5,"value":4},
{"source":7,"target":6,"value":182},
{"source":8,"target":1,"value":4},
{"source":8,"target":3,"value":14},
{"source":8,"target":4,"value":16},
{"source":8,"target":5,"value":10},
{"source":8,"target":6,"value":70},
{"source":8,"target":7,"value":18}
]
}
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.node {
stroke: #fff;
stroke-width: 1.5px;
}
.link {
stroke: #999;
stroke-opacity: .6;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 500;
var color = d3.scale.category20();
var force = d3.layout.force()
.charge(-120)
.linkDistance(30)
.size([width, height]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("departments.json", function(error, graph) {
force
.nodes(graph.nodes)
.links(graph.links)
.start();
var link = svg.selectAll(".link")
.data(graph.links)
.enter().append("line")
.attr("class", "link")
.style("stroke-width", function(d) { return Math.sqrt(d.value); });
var node = svg.selectAll(".node")
.data(graph.nodes)
.enter().append("circle")
.attr("class", "node")
.attr("r", 5)
.style("fill", function(d) { return color(d.group); })
.call(force.drag);
node.append("title")
.text(function(d) { return d.name; });
force.on("tick", function() {
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; });
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.