Skip to content

Instantly share code, notes, and snippets.

@mudspringhiker
Last active March 23, 2017 21:42
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 mudspringhiker/8ac879cc2502af58133f5222e42fd95d to your computer and use it in GitHub Desktop.
Save mudspringhiker/8ac879cc2502af58133f5222e42fd95d to your computer and use it in GitHub Desktop.
Organization Country of Nobel Laureates 1901-2017

Nobel Laureates from Different Countries

Dataset obtained from Kaggle

Summary

This data visualization maps the organization countries of Nobel Laureates from 1901 to present. A Nobel Laureate is a person or organization that gets honored for achievements in the Nobel category they are awarded.

Design

The design was chosen to easily show the countries of the Nobel Laureates. The size of the points that indicate the country also give an indication of the number of Nobel Laureates from the indicated country. In general, the map shows the distribution of the Nobel Laureates. It can be easily seen that the US has the largest number of Nobel Laureates. The map can be zoomed in and out and can be dragged using a mouse wheel or a touchpad. Also, when the cursor hovers over the points, the name of the country and the number of Nobel Laureates appear, aside from the color of the circle changing from blue to red.

Feedback

Countries with low numbers of Nobel Laureates are too small. Visualization can be more interactive.

Resources

Scott Murray's online tutorial was a great way to get my feet wet on d3.js, particularly using GeoJSON and creating maps in d3.js. The code here was mostly obtained from his tutorial and modified to obtain my objective of showing the distribution of Nobel Laureates from different countries.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Nobel Laureates</title>
<script type="text/javascript" src="https://d3js.org/d3.v3.js"></script>
<style type="text/css">
body {
background-color: gray;
font-family: Helvetica, Arial, sans-serif;
}
svg {
background-color: white;
}
#tooltip {
position: absolute;
top: 0;
left: 0;
z-index: 10;
margin: 0;
padding: 10px;
width: auto;
color: white;
font-family: sans-serif;
font-size: 10px;
text-align: left;
background-color: rgba(0, 0, 0, 0.75);
opacity: 0;
pointer-events: none;
}
#tooltip p {
margin: 0;
}
#tooltip p.value {
font-weight: light;
}
</style>
</head>
<body>
<!-- New HTML div functions as our tooltip -->
<div id="tooltip">
<p class="name"></p>
<p class="value"></p>
</div>
<script type="text/javascript">
//Globals for use later
var countries;
var nobels;
//Width and height
var w = 1000;
var h = 600;
//Define map projection
var projection = d3.geo.mercator()
.center([ 10, 30 ]) //changing the values will change location of the center. First value horizontal, second value vertical (usual cartesian positions).
.translate([ w/2, h/2 ])
.scale([ w/6 ]);
//Define path generator
var path = d3.geo.path()
.projection(projection);
//Configure zoom behavior
var zoom = d3.behavior.zoom()
.translate(projection.translate())
.scale(projection.scale())
//Defines the on("zoom") event (what to do on double-click or mousewheel roll).
.on("zoom", function(d) {
//Get the translate and scale values from this event
var t = d3.event.translate;
var s = d3.event.scale;
//Update the zoom and projection objects with these
zoom.translate(t);
projection.translate(t).scale(s);
//Recalculate countries
countries.attr("d", path);
//Recalculate nobels
nobels.attr("cx", function(d) {
return projection([d.longitude, d.latitude])[0];
})
.attr("cy", function(d) {
return projection([d.longitude, d.latitude])[1];
});
});
//Create SVG
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
//Load in GeoJSON data
d3.json("mapshaper_output.json", function(json) {
//Bind data and create one path per GeoJSON feature
// svg.selectAll("path")
// .data(json.features)
// .enter()
// .append("path")
// .attr("d", path)
// .style("fill", "#9ee0e5");
//Create a group to contain all the paths, to catch
//zoom events, even when the mouse is positioned over
//the ocean.
var countriesGroup = svg.append("g")
.attr("id", "countriesGroup")
.call(zoom); //Bind zoom listener to the countries group
//Create a rectangle in the background.
//This is purely to ensure this group fills the whole
//SVG image, so mousewheel events are caught.
countriesGroup.append("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", w)
.attr("height", h)
.style("fill", "#9ee0e5"); //Changes the color of the ocean
//Bind data and create one path per GeoJSON feature
countries = countriesGroup.selectAll("path")
.data(json.features)
.enter()
.append("path")
.attr("d", path)
.style("fill", "#fffeed");
//Load in nobels data
d3.csv("nobellist.csv", function(data) {
// scale the radius
var r = d3.scale.sqrt().range([3, 15]).domain([1, d3.max(data, function(d) {return d.Total;})]);
//Create a circle for each city
nobels = svg.selectAll("circle")
.data(data)
.enter()
.append("circle")
.attr("cx", function(d) {
return projection([d.longitude, d.latitude])[0];
})
.attr("cy", function(d) {
return projection([d.longitude, d.latitude])[1];
})
.attr("r", function(d) {
//Use r scale:
return r(d.Total);
})
.style("fill", "blue")
.style("opacity", 1)
//
//Added tooltip behavior:
//
.on("mouseover", function(d) {
//Fill yellow to highlight
d3.select(this)
.style("fill", "red");
//Position the tooltip <div> and set its content
var x = d3.event.pageX;
var y = d3.event.pageY - 40;
//Populate name in tooltip
d3.select("#tooltip .name")
.text(d.Organization_Country);
//Populate value in tooltip
d3.select("#tooltip .value")
.text("Total Nobel Laureates: " + d.Total);
//Position tooltip and make visible
d3.select("#tooltip")
.style("left", x + "px")
.style("top", y + "px")
.style("opacity", 1)
})
.on("mouseout", function() {
//Restore original fill
d3.select(this)
.style("fill", "blue");
//Hide the tooltip
d3.select("#tooltip")
.style("opacity", 0);
});
});
});
</script>
</body>
</html>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Organization_Country Chemistry Economics Medicine Peace Physics longitude latitude Total
0 Alsace (then Germany, now France) 0 0 0 0 1 2.0 47.0 1
1 Argentina 1 0 1 0 0 -65.241974 -35.112487 2
2 Australia 0 0 5 0 1 134.755 -24.776109 6
3 Austria 1 0 4 0 1 13.199959 47.200034 6
4 Belgium 1 0 4 0 1 4.66696 50.640735 6
5 Canada 3.0 0.0 2.0 0.0 2.0 -107.991707 61.066692 7
6 China 0.0 0.0 1.0 0.0 1.0 104.999927 35.000074 2
7 Czechoslovakia 1.0 0.0 0.0 0.0 0.0 -100.445882 39.78373 1
8 Denmark 1.0 1.0 4.0 0.0 3.0 10.333328 55.670249 9
9 Federal Republic of Germany 11.0 1.0 7.0 0.0 7.0 10.0 51.0 26
10 Finland 1.0 0.0 0.0 0.0 0.0 25.920916 63.246778000000006 1
11 France 11.0 2.0 10.0 1.0 16.0 1.888334 46.603354 40
12 Germany 27.0 0.0 10.0 0.0 14.0 10.423447 51.08342 51
13 Hungary 0.0 0.0 1.0 0.0 0.0 19.506094 47.181759 1
14 India 0.0 0.0 0.0 0.0 1.0 78.667743 22.351115 1
15 Ireland 0.0 0.0 0.0 0.0 1.0 -7.97946 52.865196 1
16 Israel 4.0 1.0 0.0 0.0 0.0 35.00152 30.876027 5
17 Italy 1.0 0.0 3.0 0.0 2.0 12.674297 42.638426 6
18 Japan 5.0 0.0 3.0 0.0 10.0 139.239418 36.574844 18
19 Netherlands 1.0 1.0 2.0 0.0 7.0 5.534607 52.237989 11
20 Norway 1.0 2.0 2.0 0.0 0.0 9.099972 60.500021 5
21 Portugal 0.0 0.0 2.0 0.0 0.0 -8.560792 39.430125 2
22 Russia 0.0 0.0 1.0 0.0 2.0 97.745306 64.686314 3
23 Spain 0.0 0.0 1.0 0.0 0.0 -4.003104 40.002803 1
24 Sweden 5.0 1.0 7.0 0.0 4.0 14.520858 59.674971 17
25 Switzerland 6.0 0.0 8.0 0.0 8.0 8.231974000000001 46.798562 22
26 Union of Soviet Socialist Republics 1.0 1.0 0.0 0.0 9.0 98.0 65.0 11
27 United Kingdom 28.0 6.0 31.0 0.0 26.0 -3.276575 54.702355 91
28 United States of America 79.0 65.0 112.0 3.0 104.0 -100.445882 39.78373 363
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment