Public
Edited
Dec 21, 2024
Importers
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
datasets = d3.json("https://api.beta.ons.gov.uk/v1/datasets?limit=1000")
Insert cell
Insert cell
Insert cell
dataset = datasets.items.find(item => item.id === datasetId)
Insert cell
Insert cell
editions = d3.json(
"https://api.beta.ons.gov.uk/v1/datasets/weekly-deaths-age-sex/editions"
)
Insert cell
dataset.qmi.href
Insert cell
Insert cell
version = d3.json(dataset.links.latest_version.href)
Insert cell
Insert cell
Insert cell
metadata = d3.json(version.downloads.csvw.href)
Insert cell
version.downloads.csv.href
Insert cell
Insert cell
items = d3.csv(version.downloads.csv.href, d3.autoType)

// items = d3.csv(
// withCors(
// "https://static.ons.gov.uk/datasets/weekly-deaths-age-sex-covid-19-v143.csv"
// ),
// d3.autoType
// )
Insert cell
Insert cell
Insert cell
// compacted = jsonld.expand(json) // needs CORS on https://cdn.ons.gov.uk/assets/json-ld/context.json
Insert cell
Insert cell
filtered = items
// .filter((item) => item["recorded-deaths"] === "total-registered-deaths")
.filter((item) => item["registration-or-occurrence"] === "registrations") // "occurrences"
.filter(
(item) =>
item["administrative-geography"] === "E92000001" ||
item["administrative-geography"] === "W92000004"
) // England or Wales
.filter((item) => item["V4_0"] !== null) // not empty
.filter((item) => item["age-groups"] === "all-ages")
.filter((item) => item["sex"] === "all")
Insert cell
Insert cell
Insert cell
mapped = filtered.map((item) => ({
year: item["calendar-years"],
week: Number(item["week-number"].replace(/^week-/, "")), // this should be a number already?
deaths: item["v4_0"]
}))
Insert cell
Insert cell
historical = d3.csv(await FileAttachment("weekly-deaths-region-historical@1.csv").url())
Insert cell
Insert cell
Insert cell
graph = vl
.markBar()
.title("Deaths registered per week in England and Wales")
.data(mapped.concat(historical))
.width({ step: 2 })
.encode(
vl.x().fieldO("year").axis(false),
vl
.y()
.sum("deaths")
.title("Deaths registered per week")
.axis({ grid: false }),
vl.column().fieldO("week").title("Week").spacing(0),
vl
.color()
.field("year")
.title("Year")
.scale({
range: [
"#aaa",
"#aaa",
"#aaa",
"#aaa",
"#aaa",
"#aaa",
"#aaa",
"#aaa",
"#aaa",
"#aaa",
"#f75123",
"#4a88f1",
"#51a723",
"#f7a723",
"#000000"
]
})
.legend({ orient: "bottom" }),
vl.tooltip([
{ field: "week", type: "nominal" },
{ field: "year", type: "nominal" },
{ field: "deaths", type: "quantitative" }
])
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// jsonld = require('jsonld@4.0.1/dist/jsonld.js')
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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