sec-axis
Secondary axis derived from the primary through a transformation.
transform is a function mapping a primary-axis value to its secondary-axis value. Use "identity" to mirror the primary axis exactly, or pass any callable, e.g., x => x * 9 / 5 + 32 for Celsius to Fahrenheit.
Usage
sec-axis(
transform: "identity",
name: none,
breaks: auto,
labels: auto,
)Parameters
| Parameter | Default | Description |
|---|---|---|
transform |
"identity" |
Function or "identity" mapping primary values to secondary values. |
name |
none |
Title shown above or beside the secondary axis, or none. |
breaks |
auto |
Array of break values in primary units, or auto. |
labels |
auto |
Array of labels aligned with breaks, or auto. |
Returns
Secondary axis dictionary consumed by scale-x-continuous and scale-y-continuous.
Examples
Celsius primary axis with a Fahrenheit secondary derived through a callable.
#let d = range(0, 11).map(i => (c: i * 5, mpg: i))
#plot(
data: d,
mapping: aes(x: "c", y: "mpg"),
layers: (geom-point(size: 2pt),),
scales: (
scale-x-continuous(
name: "Celsius",
secondary: sec-axis(transform: x => x * 9 / 5 + 32, name: "Fahrenheit"),
),
),
width: 10cm,
height: 6cm,
)A y secondary axis converting metres to feet, useful for dual-unit displays.
#let d = range(0, 11).map(i => (x: i, m: i * 3))
#plot(
data: d,
mapping: aes(x: "x", y: "m"),
layers: (geom-line(stroke: 1pt),),
scales: (
scale-y-continuous(
name: "Metres",
secondary: sec-axis(transform: m => m * 3.281, name: "Feet"),
),
),
width: 10cm,
height: 6cm,
)