Histogram
A histogram answers “how is this number distributed?” Plot expresses it as a rectY mark wrapped in a binX transform: the transform groups rows into bins, the mark draws a bar for each bin’s count.
```plot view=order_amountsPlot.rectY(data, Plot.binX({ y: "count" }, { x: "amount" }))```With a target line
Section titled “With a target line”```plot view=order_amounts{ marks: [ Plot.rectY(data, Plot.binX({ y: "count" }, { x: "amount" })), Plot.ruleX([100], { stroke: "tomato", strokeDasharray: "4 2" }), ]}```Stacked by group
Section titled “Stacked by group”Pass a fill channel; bins stack by group at each x.
```plot view=order_amounts_by_segmentPlot.rectY(data, Plot.binX({ y: "count" }, { x: "amount", fill: "segment" }))```Common options
Section titled “Common options”| Option | Meaning |
|---|---|
x | column name (the numeric variable being binned) |
thresholds | bin count, e.g. 24; or an array of cut points; or a function |
fill | column name → grouping (rows in the same bin stack by this) |
Plot.binX({ y: "count" }, ...) | count rows per bin (most common) |
Plot.binX({ y: "sum" }, ...) | sum a column per bin (set y2: "amount") |
Plot.binX({ y: "mean" }, ...) | mean a column per bin |
interval | for date bins: "day", "month", "year", etc. |
cumulative | true for a cumulative histogram |
See Observable Plot — bin and rect.