Published
Edited
Sep 4, 2020
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md`<h3>3. Proportion of each cause in the excess</h3>
<p>...</p>`
Insert cell
Insert cell
pieCause(4)
Insert cell
Insert cell
Insert cell
pieCause(12)
Insert cell
Insert cell
Insert cell
Insert cell
md`<p>Let's see this in the map:</p>`
Insert cell
Insert cell
{
let div = DOM.element('div');
let states = Object.keys(excessStates).map(name => excessStates[name].code);
let trace = {
type: 'choropleth',
locationmode: 'USA-states',
locations: states,
z: states.map(s => {
let stname = statecode.filter(x => x.code == s)[0].state;
let stateData = excessStates[stname];
// excess mortality from all causes
let allCause = stateData.all
.map(x => (x['All Cause'] || 0) - x['Average 2015-2019'])
.reduce((a, b) => a + b);
let ofCovid = stateData.covid.map(
x => (x['of COVID'] || 0) - x['Average 2015-2019']
);
if (ofCovid.length > 0) {
ofCovid = ofCovid.reduce((a, b) => a + b);
} else {
ofCovid = NaN;
}
return Math.round(100 * Math.max(1 - ofCovid / allCause, 0));
}),
text: states.map(s => statecode.filter(x => x.code == s)[0].state)
};
Plotly.plot(div, [trace], {
title: '% of additional mortality that is not by COVID',
geo: {
scope: 'usa',
showlakes: true,
lakecolor: 'rgb(255,255,255)'
},
dragmode: false
});
return div;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require('d3')
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