scale-x-continuous

Continuous x scale: axis title, limits, breaks, labels, and transformation.

transform accepts "identity", "log10", "sqrt", and "reverse".

Usage

scale-x-continuous(
  name: none,
  limits: none,
  oob: "drop",
  breaks: auto,
  minor-breaks: auto,
  n-minor: auto,
  labels: auto,
  transform: "identity",
  expand: auto,
  secondary: none,
)

Parameters

Parameter Default Description
name none Axis title. Overrides any name set via labels when both are present.
limits none Pair (lo, hi) clipping the trained domain, or none for automatic limits. Either element may be auto to keep the trained bound on that side.
oob "drop" Out-of-range policy: "drop" (default) removes rows whose value falls outside limits; "squish" clamps them to the nearest endpoint.
breaks auto Array of break values, or auto for automatic tick selection.
minor-breaks auto Array of minor gridline positions, or auto to derive them automatically (midpoints between major breaks, extended one step beyond each end).
n-minor auto Number of minor gridlines between adjacent major breaks when minor-breaks is auto; auto resolves to 1.
labels auto Array of tick labels aligned with breaks, or auto.
transform "identity" Transformation keyword: "identity", "log10", "sqrt", or "reverse".
expand auto Padding around the domain. Accepts a ratio (5%) for proportional breathing room, a length (5pt) for canvas-space padding, a relative (5pt + 5%) for both, or a (lo, hi) 2-tuple for asymmetric padding, where either element may be auto to keep the per-scale default on that side. auto keeps the per-scale default; false collapses to zero.
secondary none Secondary axis spec from dup-axis or sec-axis, or none.

Returns

Scale object consumed by plot.

Examples

Override the axis title and pin the domain.

#let d = range(1, 11).map(i => (x: i, y: i * i))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-point(size: 2pt),),
  scales: (scale-x-continuous(name: "Index", limits: (0, 12)),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of ten squared values where scale-x-continuous renames the x axis to Index and pins its domain to 0 through 12.

Scatter chart of ten squared values where scale-x-continuous renames the x axis to Index and pins its domain to 0 through 12.

Switch transform to "sqrt" and supply explicit breaks for a custom non-linear axis.

#let d = range(0, 11).map(i => (x: i * i, y: i))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-point(size: 2pt),),
  scales: (scale-x-continuous(
    name: "x (sqrt)",
    transform: "sqrt",
    breaks: (0, 25, 50, 75, 100),
  ),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of eleven points on a square-root x axis with manual breaks at 0, 25, 50, 75, 100 that straighten the quadratic relationship.

Scatter chart of eleven points on a square-root x axis with manual breaks at 0, 25, 50, 75, 100 that straighten the quadratic relationship.

Apply format-comma() to format penguin body-mass tick labels with thousands separators on the x axis.

#plot(
  data: penguins,
  mapping: aes(x: "body-mass", y: "flipper-len", fill: "species"),
  layers: (geom-point(size: 2pt),),
  scales: (scale-x-continuous(name: "Body mass (g)", labels: format-comma()),),
  width: 11cm,
  height: 6cm,
)

Scatter chart of penguin body mass against flipper length coloured by species, with x-axis ticks formatted using comma thousands separators.

Scatter chart of penguin body mass against flipper length coloured by species, with x-axis ticks formatted using comma thousands separators.

See also

scale-y-continuous, scale-x-discrete, coord-cartesian.

Back to top