Published
Edited
Apr 8, 2020
Insert cell
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, 40]}),
vl.y().fieldQ("count").axis({ title: 'Deaths' }).scale({ domain: [1, 7000]}),
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
rawDataNHS = d3.csvParse(await FileAttachment("nhsdata@1.csv").text());
Insert cell
rawDataNHS2 = d3.csvParse(await FileAttachment("20200407_nhsdata.csv").text());
Insert cell
rawDataJohnHopkins = d3.csvParse(await FileAttachment("20200408deaths.csv").text());
Insert cell
ukData = rawDataJohnHopkins.find((item) => (item['Country/Region'] === 'United Kingdom' && item['Province/State'] === ''))
Insert cell

x = {
let i = 41;
while (true) {
--i
if (i === -1) {
i = 41;
yield Promises.delay(20000, i);
}
yield Promises.delay(250, i);
}
}
Insert cell
englangNHSData = rawDataNHS.find((item) => (item['NHS England Region'] === 'England'))
Insert cell
englangNHS2Data = rawDataNHS2.find((item) => (item['NHS England Region'] === '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
transformFuncNhs = (data, country) => R.compose(
R.dropLast(x),
(item) => {
const toSum = [];
const all = [];
item.forEach((current, index) => {
toSum.push(parseInt(current, 10))
all.push({day: index, count: R.sum(toSum), country});
});
return all;
},
// R.last,
// R.splitWhen((x) => (x !== "0")),
R.values,
R.omit(['NHS England Region', ''])
)(data)
Insert cell
transformFuncJohnHopkins = (data, country) => R.compose(
R.dropLast(x),
(item) => {
const all = [];
item.forEach((current, index) => {
all.push({day: index, count: parseInt(current, 10), country});
});
return all;
},
R.map((item) => (item[1])),
R.last,
R.splitWhen((x) => (x[0] === "2/29/20")),
R.toPairs,
R.omit(['Province/State', 'Country/Region', 'Lat', 'Long'])
)(data)
Insert cell
all = (() => {
return [].concat(transformFuncNhs(englangNHSData, 'England NHS Data 5/4/20'), transformFuncJohnHopkins(ukData, 'UK John Hopkins 7/4/20'), transformFuncNhs(englangNHS2Data, 'England NHS Data 7/4/20'));
})();
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