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,
)

Scatter chart of a sinusoidal series along an x axis cut into five equal-width bins whose midpoints place the tick labels.

Scatter chart of a sinusoidal series along an x axis cut into five equal-width bins whose midpoints place the tick labels.

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,
)

Scatter chart of a sinusoidal series along an x axis cut into ten finer bins and clipped to limits 2 through 8 to zoom into a sub-range.

Scatter chart of a sinusoidal series along an x axis cut into ten finer bins and clipped to limits 2 through 8 to zoom into a sub-range.

See also

scale-y-binned, scale-x-continuous.

Back to top