Published
Edited
May 8, 2019
Insert cell
md`# summary statistics by universities`
Insert cell
z = require('https://bundle.run/zebras@0.0.11')
Insert cell
vegalite = require("@observablehq/vega-lite@0.1")
Insert cell
d3 = require("d3-fetch@1")
Insert cell
d3v4 = require("d3@4")
Insert cell
inflowData=d3.csv("https://gist.githubusercontent.com/ycfan14/ec535938a24f11054d0e3dffee9feeb6/raw/9c6f2d2df925a6e9ea17c63e8544e4d8d70cfaf1/gistfile1.txt")
Insert cell
outflowData=d3.csv("https://gist.githubusercontent.com/ycfan14/951a95637916e7f3f84f2abfb4e5f369/raw/1ce84c367984a9d7dacbec04b02e76eb66114c14/gistfile1.txthttps://gist.githubusercontent.com/ycfan14/951a95637916e7f3f84f2abfb4e5f369/raw/1ce84c367984a9d7dacbec04b02e76eb66114c14/gistfile1.txt")
Insert cell
yearList={
var tem= z.unique(z.getCol("year",InflowParse))
return tem
}
Insert cell
InflowParse={
var InflowParse=inflowData
for (var i=1; i<=20;i++){
var variable=inflowData.columns[i]
InflowParse=z.dropCol("BERKELEY", z.parseNums(variable, InflowParse))
}
return InflowParse
}
Insert cell
OutflowParse={
var OutflowParse=outflowData
for (var i=1; i<=21;i++){
var variable=outflowData.columns[i]
OutflowParse=z.dropCol("BERKELEY", z.parseNums(variable, OutflowParse))
}
return OutflowParse
}
Insert cell
InflowReshape={
var reshape=[]
for (var j=1;j<=21;j++){
for (var i=0; i<=6;i++){
var variable=inflowData.columns[j]
reshape.push({"University":variable, "year":yearList[i],"number":InflowParse[i][variable]})
}
}
var reshape2=z.filter(r=>r.University!="BERKELEY", reshape)
return reshape2
}
Insert cell
OutflowReshape={
var reshape=[]
for (var j=1;j<=21;j++){
for (var i=0; i<=6;i++){
var variable=outflowData.columns[j]
reshape.push({"University":variable, "year":yearList[i],"number":OutflowParse[i][variable]})
}
}
var reshape2=z.filter(r=>r.University!="BERKELEY", reshape)
return reshape2
}
Insert cell
selectedData = {
switch (chartType) {
case "Inflow": return InflowReshape
case "Outflow": return OutflowReshape
}
}
Insert cell
Insert cell
vegalite({
$schema: "https://vega.github.io/schema/vega-lite/v3.json",
width: 400,
height: 400,
title: "Talents Inflow",
data: {values: selectedData},
mark: {type: "line", tooltip: {"content": "data"}},
encoding: {
x: {field: "year", type: "temporal",
axis: {title: "Year",tickWidth: 5}},
y: {field: "number", type: "quantitative",
axis: {title: "Number of talents migrating"}} ,
color: {field: "University", type: "nominal"}
}
})
Insert cell
Insert cell
embed = require("vega-embed@3")
Insert cell
Insert cell
d3_5 = require("d3@5")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more