Plot.plot({
caption: "Chicago crash deaths",
style: "overflow: visible;",
caption: "Annual cumulative traffic deaths by day of years in Chicago",
y: {
grid: true,
label: "Deaths"
},
color: {
domain: [false, true],
range: ["#ccc", "red"]
},
marks: [
Plot.line(
chicagoCrashDeaths,
Plot.mapY("cumsum", {
x: (d) =>
new Date(2020, d.crash_date.getMonth(), d.crash_date.getDate()),
y: (d) => 1,
z: (d) => d.crash_date.getFullYear(),
stroke: (d) => new Date().getFullYear() === d.crash_date.getFullYear(),
curve: "step-before"
})
),
Plot.text(
chicagoCrashDeaths,
Plot.selectLast(
Plot.mapY("cumsum", {
x: (d) =>
new Date(2020, d.crash_date.getMonth(), d.crash_date.getDate()),
y: (d) => 1,
z: (d) => d.crash_date.getFullYear(),
text: (d) => d.crash_date.getFullYear().toString(),
textAnchor: "start",
dx: 3,
dy: -2
})
)
),
Plot.axisX({
ticks: "month",
tickSize: 16,
tickPadding: -11,
tickFormat: " %b",
textAnchor: "start"
})
]
})