Published
Edited
Mar 20, 2018
Insert cell
Insert cell
Insert cell
VegaliteTooltip({
'$schema': 'https://vega.github.io/schema/vega-lite/v2.json',
'title': 'Refugee immigration to US from travel ban countries (Iran, Libya, Somalia, Sudan, Syria, and Yemen)',
'width': 800, 'height': 300,
'layer': [
{
'data': {'values': timeline},
'transform': [{
'filter': 'datum.Day >= datetime(2012, 1, 1) && indexof(["Christian", "Muslim"], datum.Religion) != -1 && indexof(["Somalia", "Libya", "Iran", "Sudan", "Syria", "Yemen"], datum.Country) != -1',
}],
'mark': 'line',
'encoding': {
'x': {
'timeUnit': 'yearmonth', 'field': 'Day', 'type': 'temporal',
'axis': {'domain': false, 'tickSize': 0, 'title': 'Day'}
},
'y': {
'aggregate': 'sum', 'field': 'Count','type': 'quantitative', 'name': 'Total arrivals',
'axis': {'domain': false, 'title': 'Total arrivals'},
},
'color': {'field': 'Religion', 'type': 'nominal'}
},
},
{
'data': {'values': [
{'Day': '2017-01-20', 'Label': '← Trump enters office'},
]},
'layer': [
{
'mark': 'rule',
'encoding': {
'x': {
'timeUnit': 'yearmonth', 'field': 'Day', 'type': 'temporal',
'aggregate': 'min',
'axis': null,
},
'size': {'value': 2},
'color': {'value': 'black',}
},
},
{
'mark': {
'type': 'text',
'align': 'left',
'baseline': 'top',
'dy': -62,
'dx': 10,
},
'encoding': {
'x': {
'timeUnit': 'yearmonth', 'field': 'Day', 'type': 'temporal',
'aggregate': 'min',
'axis': null,
},
'text': {'field': 'Label', 'type': 'nominal'},
'color': {'value': 'black',}
},
},
],
},
],
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
rc['Moslem']
Insert cell
rc['Moslem Suni'] + rc['Moslem Shiite']
Insert cell
VegaliteTooltip({
data: {values: religionCounts},
title: `Refugee arrivals to US by Religion, 2002-2018`,
mark: 'bar',
encoding: {
x: {field: 'Religion', type: 'ordinal', sort: {field: 'value', type: 'quantitative', type: 'descending'}},
y: {field: 'Count', type: 'quantitative'},
},
})
Insert cell
Insert cell
religionCounts = {
let religionCol, countCol;
const religions = new Map();
refugeesByReligion.scan(
(idx) => {
const religion = religionCol(idx);
const count = countCol(idx);
if (religions.has(religion)) {
religions.set(religion, religions.get(religion) + count);
} else {
religions.set(religion, count);
};
},
(batch) => {
religionCol = arrow.predicate.col('religion').bind(batch);
countCol = arrow.predicate.col('count').bind(batch);
},
);
return Array.from(religions.entries()).sort((a, b) => a[1] > b[1] ? -1 : (a[1] < b[1] ? 1 : 0)).map((x) => ({Religion: x[0], Count: x[1]}));
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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