violin = Plot.plot({
height:90,
x: {domain: d3.extent(data, d=> d.temperature)},
marks: [
() => htl.svg`<defs>
<linearGradient id="gradient">
<stop offset="0%" style="stop-color: #cbe4ee;"/>
filter <stop offset="35%" style="stop-color: #f9f8c8"/>
<stop offset="100%" style="stop-color: #e17851;"/>
</linearGradient>
</defs>`,
Plot.areaY(data.filter(d=> d.year === '2010'),
Plot.binX(
{
y: "count",
},
{
x: "temperature",
fill: "url(#gradient)",
curve: "basis",
offset: "center"
}
)),
Plot.ruleX([d3.mean(data, (d) => d.temperature)], { stroke: "#808080" }),
Plot.textX([d3.mean(data, (d) => d.temperature)], {
y: 110,
textAnchor: "start",
text: (d) => `Avg. temp. 1981-2023: ${d3.format(".1f")(d)}ºC`,
fontWeight: "bold",
dx: 5
}),
]
})