scale-x-binned
Binned continuous x scale: quantises a numeric axis into n-breaks bins.
Keeps the underlying mapping continuous so geoms still receive their raw numeric position, but places ticks at the midpoint of each equal-width bin to communicate the discretised reading of the axis.
Usage
scale-x-binned(
name: none,
limits: none,
n-breaks: 10,
labels: auto,
)Parameters
| Parameter | Default | Description |
|---|---|---|
name |
none |
Axis title. Overrides any name set via labs when both are present. |
limits |
none |
Pair (lo, hi) clipping the trained domain, or none. |
n-breaks |
10 |
Number of bins to partition the domain into. |
labels |
auto |
Array of tick labels aligned with the bin midpoints, or auto. |
Returns
Scale object consumed by plot.
Examples
Five equal-width bins along the x axis.
#let d = range(0, 30).map(i => (x: i / 3.0, y: calc.sin(i / 4.0)))
#plot(
data: d,
mapping: aes(x: "x", y: "y"),
layers: (geom-point(size: 2pt),),
scales: (scale-x-binned(n-breaks: 5),),
width: 10cm,
height: 6cm,
)Bump n-breaks for a finer grid; pair with limits to focus on a sub-range.
#let d = range(0, 30).map(i => (x: i / 3.0, y: calc.sin(i / 4.0)))
#plot(
data: d,
mapping: aes(x: "x", y: "y"),
layers: (geom-point(size: 2pt),),
scales: (scale-x-binned(n-breaks: 10, limits: (2, 8)),),
width: 10cm,
height: 6cm,
)