-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplot1.js
More file actions
33 lines (32 loc) · 1.03 KB
/
plot1.js
File metadata and controls
33 lines (32 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Plotly.d3.csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv', function(err, rows){
var YEAR = 2007;
var continents = ['Asia', 'Europe', 'Africa', 'Oceania', 'Americas'];
var POP_TO_PX_SIZE = 2e5;
function unpack(rows, key) {
return rows.map(function(row) { return row[key]; });
}
var data = continents.map(function(continent) {
var rowsFiltered = rows.filter(function(row) {
return (row.continent === continent) && (+row.year === YEAR);
});
return {
mode: 'markers',
name: continent,
x: unpack(rowsFiltered, 'lifeExp'),
y: unpack(rowsFiltered, 'gdpPercap'),
text: unpack(rowsFiltered, 'country'),
marker: {
sizemode: 'area',
size: unpack(rowsFiltered, 'pop'),
sizeref: POP_TO_PX_SIZE
}
};
});
var layout = {
xaxis: {title: 'Life Expectancy'},
yaxis: {title: 'GDP per Capita', type: 'log'},
margin: {t: 20},
hovermode: 'closest'
};
Plotly.plot('my-graph', data, layout, {showLink: false});
});