scale-x-reverse

Continuous x scale flipped left-to-right.

Thin wrapper over scale-x-continuous with transform: "reverse". Tick labels stay in data units; only the axis direction reverses.

Usage

scale-x-reverse(
  name: none,
  limits: none,
  oob: "drop",
  breaks: auto,
  minor-breaks: auto,
  n-minor: auto,
  labels: auto,
)

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.

Returns

Scale object consumed by plot.

Examples

Reverse the x axis so values decrease left-to-right.

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

Scatter chart of ten points along a reversed x axis where values decrease from left to right while tick labels remain in data units.

Scatter chart of ten points along a reversed x axis where values decrease from left to right while tick labels remain in data units.

Pair with limits to clip a reversed timeline to a specific window.

#let d = range(2000, 2025).map(y => (x: y, y: calc.sin(y / 4)))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-line(stroke: 1pt),),
  scales: (scale-x-reverse(name: "Year", limits: (2024, 2010)),),
  width: 10cm,
  height: 6cm,
)

Line chart of a sinusoidal series on a reversed x axis clipped to years 2024 through 2010 so the timeline reads from right to left.

Line chart of a sinusoidal series on a reversed x axis clipped to years 2024 through 2010 so the timeline reads from right to left.

See also

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

Back to top