Horizon chart
Horizon charts are an alternative to ridgeline plots and small-multiple area charts that allow greater precision for a given vertical space by using colored bands. These charts can be used with diverging color scales to differentiate positive and negative values. Data: Christopher Möller.
const chart = Plot.plot({
height: 1100,
width: 928,
x: {axis: "top"},
y: {domain: [0, step], axis: null},
fy: {axis: null, domain: traffic.map((d) => d.location), padding: 0.05},
color: {
type: "ordinal",
range: dark ? [...d3.schemeGreens[bands + 1]].reverse() : d3.schemeGreens[bands],
label: "Vehicles per hour",
tickFormat: (i) => ((i + 1) * step).toLocaleString("en"),
legend: true
},
marks: [
d3.range(bands).map((band) =>
Plot.areaY(traffic, {
x: "date",
y: (d) => d.vehicles - band * step,
fy: "location",
fill: band,
sort: "date",
clip: true
})
),
Plot.axisFy({
frameAnchor: "left",
dx: -28,
fill: "currentColor",
textStroke: "var(--plot-background)",
label: null
})
]
});
display(chart);
const traffic = FileAttachment("../data/traffic.csv").csv({typed: true});
const step = (d3.max(traffic, (d) => d.vehicles) / bands).toPrecision(2);