For the counts, you could use a group transform:
Plot.plot({
marginLeft: 70,
width,
color: { scheme: "YlGnBu" },
y: { axis: null },
marks: [
Plot.barX(
data,
Plot.binX(
{ filter: (x) => x.length === 0 },
{ x: "date", y: "category", thresholds: d3.utcWeek, fill: "#eee" }
)
),
Plot.barX(
data,
Plot.binX(
{ fill: "count" },
{ x: "date", y: "category", thresholds: d3.utcWeek }
)
),
Plot.text(
data,
Plot.selectFirst({
x: d3.min(data, (d) => d.date),
y: "category",
z: "category",
text: d => d.category?.toUpperCase(),
textAnchor: "end",
dx: -10
})
),
Plot.text(
data,
Plot.groupY(
{ text: "count" },
{
x: d3.max(data, (d) => d.date),
y: "category",
textAnchor: "end",
dx: 32
}
)
)
]
})
Finally, to create svgs instead of text labels, you can replace the corresponding Plot.text by a Plot.image mark.
