scale-binned

Binned scale that quantises a continuous variable into n-breaks bins.

Valid on x/y, size, alpha, linewidth, stroke, shape, and linetype; the per-row mapping stays continuous while the legend or axis snaps to bin midpoints.

Usage

scale-binned(
  ..args,
)

Parameters

Parameter Default Description
..args Named arguments forwarded to the bound scale (e.g. n-breaks, breaks, name, limits, and range or palette).

Returns

Deferred scale spec consumed by scales.

Examples

Quantise the x axis into five equal-width bins.

#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: scales(x: scale-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.

See also

scales, scale-continuous.

Back to top