Published
Edited
Jun 26, 2020
Insert cell
Insert cell
viewof line = vl.markLine()
.width(750)
.height(400)
.data(all)
.encode(
vl.x().fieldQ("day").axis({ title: 'Days since first death in country' }).scale({domain: [0, 120]}),
vl.y().fieldQ("count").axis({ title: 'Deaths' }).scale(scaleObject),
vl.color().fieldN("country")
)
.render()
Insert cell
d3 = require("d3@5")
Insert cell
import {vl} from '@vega/vega-lite-api';
Insert cell
R = require("ramda")
Insert cell
rawData = d3.csvParse(await FileAttachment("20060625nhscoviddeathsbyage.csv").text());
Insert cell

x = {
let i = Object.keys(rawData[0]).length;
while (true) {
--i
if (i === -1) {
i = Object.keys(rawData[0]).length - 1;
yield Promises.delay(20000, i);
}
yield Promises.delay(250, i);
}
}
Insert cell
set2 = rawData.find((item) => (item['Age group'] === '20 - 39'))
Insert cell
set3 = rawData.find((item) => (item['Age group'] === '40 - 59'))
Insert cell
set4 = rawData.find((item) => (item['Age group'] === '60 - 79'))
Insert cell
set5 = rawData.find((item) => (item['Age group'] === '80+'))
Insert cell
// Omit data not needed, find the first day that is not 0 (first death) and use as day 0, prepare for graph
transformFunc = (data, country) => R.compose(
R.dropLast(x),
(item) => {
const toSum = [];
const all = [];
item.forEach((current, index) => {
all.push({day: index, count: parseInt(current, 10), country});
});
return all;
},
// R.last,
// R.splitWhen((x) => (x !== "0")),
R.values,
R.omit(['Age group', ''])
)(data)
Insert cell
all = (() => {
return [].concat(transformFunc(set2, '20 - 39'), transformFunc(set3, '40 - 59'), transformFunc(set4, '60 - 79'), transformFunc(set5, '80+'))
})();
Insert cell
scales = ['linear', 'log']
Insert cell
comparisonTypes = ['Actual', 'Cases per hundred thousand population']
Insert cell
scaleObject = ({ domain: [1, 500]});
Insert cell
html`<code>css</code> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.0/css/bootstrap.min.css" integrity="sha384-PDle/QlgIONtM1aqA2Qemk5gPOE7wFq8+Em+G/hmo5Iq0CCmYZLv3fVRDJ4MMwEA" crossorigin="anonymous">`
Insert cell
$ = require('jquery').then(jquery => {
window.jquery = jquery;
return require('popper@1.0.1/index.js').catch(() => jquery);
})
Insert cell
bootstrap = require('bootstrap')
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