Binned box plot
The box mark expects a quantitative dimension (for its extent, here, y, representing price), and optionally an ordinal dimension. The example below uses the [scale interval option](plot to convert carats (a quantitative dimension) into a usable ordinal dimension, on fx. If you are interested in ways to make this easier, please upvote #1330.
Plot.plot({
marginLeft: 60,
y: {
grid: true,
label: "↑ Price"
},
fx: {
interval: 0.5,
label: "Carats →",
labelAnchor: "right",
tickFormat: (x) => x.toFixed(1)
},
marks: [
Plot.ruleY([0]),
Plot.boxY(diamonds, {fx: "carat", y: "price"})
]
})
const diamonds = FileAttachment("data/diamonds.csv").csv({typed: true}).then(display);