Published
Edited
May 18, 2022
Fork of PSI Workshop
1 fork
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
import {db} from "@observablehq/psi-data"
Insert cell
db.describe()
Insert cell
Insert cell
Insert cell
db
select * from reported
-- WHERE loc_type = 'CITY'
where incidence > 100
Insert cell
Insert cell
Insert cell
db
select SUM(cases)::INT cases, disease, date from reported
where date > ${new Date(minYear, 0, 1)} AND
disease <> 'MEASLES'
group by disease, date
order by date
Insert cell
import { addTooltips } from "@mkfreeman/plot-tooltip"
Insert cell
addTooltips(
Plot.plot({
width,
marks: [
Plot.dot(byDate, {
x: "date",
y: "cases",
stroke: "disease",
title: (d) => `${d.disease}: ${d.cases} cases`
}),
Plot.ruleY([0])
],
y: {
type: "log"
},
color: {
legend: true
}
})
)
Insert cell
Insert cell
db
SELECT DISTINCT(disease) from reported
Insert cell
db
select incidence, state, date from reported
where disease = ${disease} AND loc_type='STATE'
ORDER BY state, date
Insert cell
Insert cell
timeChart = Plot.plot({
width,
marks: [
Plot.lineY(
byState,
Plot.windowY({
x: "date",
y: "incidence",
stroke: "state",
k: 10,
reduce: "mean"
})
),
Plot.text(
byState,
Plot.selectMaxY(
Plot.windowY({
x: "date",
y: "incidence",
fill: "state",
text: "state",
dy: -10,
k: 10,
reduce: "mean"
})
)
),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
import { Choropleth, states } from "@d3/state-choropleth"
Insert cell
db
select avg(incidence) incidence, fips.state, fips.fips from reported
left join fips on reported.state = fips.state
where disease=${disease}
group by fips.state, fips.fips
Insert cell
chart = addTooltips(
Choropleth(incidence, {
id: (d) => d.fips,
value: (d) => d.incidence,
features: states,
width: 975,
height: 610
}),
{ stroke: "black" }
)
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