dup-axis

Duplicate the primary axis on the opposite side of the panel.

Since 0.0.1.

Draws the same ticks as the primary axis but on the top edge for x or the right edge for y, optionally with a different title.

Usage

dup-axis(
  name: none,
  breaks: auto,
  labels: auto,
)

Parameters

Parameter Default Description
name none Title shown above or beside the secondary axis, or none.
breaks auto Array of break values in primary units, a function of the trained values returning them (the breaks-* helpers return such a function), or auto to mirror the primary axis.
labels auto Array of labels aligned with breaks, a function of the break value, or auto to format each break.

Returns

Secondary axis dictionary consumed by scale-continuous and scale-continuous.

Examples

Mirror the x axis on top with a different title.

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

Scatter chart of eleven squared values where the bottom x axis is duplicated on top edge with a different title via dup-axis.

Scatter chart of eleven squared values where the bottom x axis is duplicated on top edge with a different title via dup-axis.

Mirror the y axis on the right with custom break positions.

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

Scatter chart of eleven squared values where the left y axis is mirrored on the right edge with custom breaks at 0, 25, 50, 75, 100.

Scatter chart of eleven squared values where the left y axis is mirrored on the right edge with custom breaks at 0, 25, 50, 75, 100.

See also

sec-axis, scale-continuous.

Back to top