Public
Edited
Feb 13, 2023
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chart = addTooltips(Plot.plot({
height: 600,
width: width,
y: {
axis: null,
domain: [0, d3.max(data, d => d.y) / (overlap + 1)]
},
x: {
label: "mean no. of infected neighboring nodes →"
},
fy: {
axis: "left",
label: "CDC week",
tickFormat: d => formatDate(cdc[d]),
},
facet: {
data: data,
y: "week",
x: "network",
marginLeft:100
},
style: {
pointerEvents: "all"
},
marks: [
Plot.areaY(data, {x: "x", y:"y", fillOpacity: 0.5, fill: d => color(getDiff(d)), title: d => `week ${d.week}\np-value: ${d.pval}`}),
Plot.lineY(data, {x: "x", y: "y", strokeWidth: 1}),
Plot.ruleX(data, Plot.selectLast({x: "obs", strokeOpacity: 0.5, stroke: "red", strokeWidth: 5, title: d => `observed mean: ${d.obs}`}))
]
}), { fill: "gray", opacity: 0.5, "stroke-width": "3px", stroke: "pink" })
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
formatDate = d3.timeFormat("%d %b %Y")
Insert cell
color = d3.scaleSequential([-1, 1], d3.interpolateViridis);
Insert cell
diffPhone = {
const data = d3.csvParse(await FileAttachment("phone_salience_ktest_random.csv").text(), d3.autoType);
const raw = d3.group(data, d => d.week);
const parsed = {};
raw.forEach((val, w) => parsed[w] = (ps_obs[w].obs - d3.mean(val.map(d => d["infecteds.mean"]))));
return parsed;
}
Insert cell
diffFlight = {
const data = d3.csvParse(await FileAttachment("flight_salience_ktest_random.csv").text(), d3.autoType);
const raw = d3.group(data, d => d.week);
const parsed = {};
raw.forEach((val, w) => parsed[w] = (fs_obs[w].obs - d3.mean(val.map(d => d["infecteds.mean"]))));
return parsed;
}
Insert cell
getDiff = (d) => {
if (d.network == "flight salience") return diffFlight[d.week];
if (d.network == "phone salience") return diffPhone[d.week];
}
Insert cell
Insert cell
Insert cell
ps_obs = {
const ps_obs = d3.csvParse(await FileAttachment("phone_salience_ktest_obs.csv").text(), d3.autoType);
return ps_obs.reduce((map, obj) => (map[obj.week] = {obs: obj["obs.vals"], pval: obj["pval"]}, map), {});
}
Insert cell
Insert cell
Insert cell
Insert cell
data1 = d3.csvParse(await FileAttachment("phone_salience_ktest_random.csv").text(), d3.autoType);
Insert cell
data1
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
kde = require('fast-kde')
Insert cell
import {addTooltips} from "@mkfreeman/plot-tooltip"
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