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("20060625nhscoviddeaths@2.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['region'] === 'London'))
Insert cell
set3 = rawData.find((item) => (item['region'] === 'Midlands'))
Insert cell
set4 = rawData.find((item) => (item['region'] === 'North East And Yorkshire'))
Insert cell
set5 = rawData.find((item) => (item['region'] === 'North West'))
Insert cell
set6 = rawData.find((item) => (item['region'] === 'South East'))
Insert cell
set7 = rawData.find((item) => (item['region'] === 'South West'))
Insert cell
set8 = rawData.find((item) => (item['region'] === 'East Of England'))
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, 'London'), transformFunc(set3, 'Midlands'), transformFunc(set4, 'North East And Yorkshire'), transformFunc(set5, 'North West'), transformFunc(set6, 'South East'), transformFunc(set7, 'South West'), transformFunc(set8, 'East Of England'))
})();
Insert cell
scales = ['linear', 'log']
Insert cell
comparisonTypes = ['Actual', 'Cases per hundred thousand population']
Insert cell
scaleObject = ({ domain: [1, 300]});
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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more