expand-limits

Ensure the trained domain includes the supplied values without replacing it.

expand-limits does not clip the data; it folds extend values into the trained min/max so the final domain spans both the data and the supplied points. Useful for forcing a baseline at zero or showing a target value alongside observed data.

Usage

expand-limits(
  x: none,
  y: none,
)

Parameters

Parameter Default Description
x none Single value or array of values the x-axis must include, or none.
y none Single value or array of values the y-axis must include, or none.

Returns

Array of scale specs ready to splat into scales: on plot.

Examples

Force a y baseline at zero so positive observations sit above the axis floor.

#let d = range(1, 6).map(i => (x: i, y: i))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-point(size: 3pt),),
  scales: expand-limits(y: 0),
  width: 10cm,
  height: 6cm,
)

Scatter chart of y against x whose y axis is extended to include zero via expand-limits, so all positive points sit above the baseline.

Scatter chart of y against x whose y axis is extended to include zero via expand-limits, so all positive points sit above the baseline.

Pass arrays to extend both axes towards multiple targets at once, useful for highlighting a reference value.

#let d = range(1, 6).map(i => (x: i, y: i))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-point(size: 3pt),),
  scales: expand-limits(x: (0, 10), y: (0, 10)),
  width: 10cm,
  height: 6cm,
)

Scatter chart of y against x with both axes extended to span zero to ten via expand-limits, leaving extra empty space around the data.

Scatter chart of y against x with both axes extended to span zero to ten via expand-limits, leaving extra empty space around the data.

See also

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

Back to top