scale-x-sqrt

Continuous x scale on a square-root axis.

Thin wrapper over scale-x-continuous with transform: "sqrt". All x values must be non-negative.

Usage

scale-x-sqrt(
  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

Square-root x axis spreads small values and compresses large ones.

#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-sqrt(name: "x"),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of eleven squared values on a square-root x axis that spreads small values and compresses large ones into evenly spaced ticks.

Scatter chart of eleven squared values on a square-root x axis that spreads small values and compresses large ones into evenly spaced ticks.

Pin breaks at perfect squares so the labels match the underlying data structure.

#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-sqrt(
    name: "x",
    breaks: (0, 4, 16, 36, 64, 100),
  ),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of eleven points on a square-root x axis with breaks pinned at perfect squares 0, 4, 16, 36, 64, 100 for evenly placed labels.

Scatter chart of eleven points on a square-root x axis with breaks pinned at perfect squares 0, 4, 16, 36, 64, 100 for evenly placed labels.

See also

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

Back to top