scales

Bind scale specifications to aesthetics.

Accepts named arguments where each key is an aesthetic (e.g., x, colour, fill) and each value is a scale spec from a scale-* constructor, or auto to keep the default scale. The resulting dictionary threads into the plot spec and is honoured by scale training. When two entries target the same aesthetic the later one wins, matching guides.

Usage

scales(
  ..args,
)

Parameters

Parameter Default Description
..args Named scale specs keyed by aesthetic name.

Keys accepted by ..args:

  • x: a scale spec for the x aesthetic, or auto for the default.
  • y: a scale spec for the y aesthetic, or auto for the default.
  • colour: a scale spec for the colour aesthetic, or auto for the default.
  • fill: a scale spec for the fill aesthetic, or auto for the default.
  • size: a scale spec for the size aesthetic, or auto for the default.
  • alpha: a scale spec for the alpha aesthetic, or auto for the default.
  • linewidth: a scale spec for the linewidth aesthetic, or auto for the default.
  • stroke: a scale spec for the stroke aesthetic, or auto for the default.
  • shape: a scale spec for the shape aesthetic, or auto for the default.
  • linetype: a scale spec for the linetype aesthetic, or auto for the default.

Returns

Dictionary mapping aesthetic name to scale spec.

Examples

Pin the x domain and colour the points with a discrete viridis palette in one keyed call.

#let d = (
  (x: 1, y: 1, g: "a"),
  (x: 2, y: 2, g: "b"),
  (x: 3, y: 3, g: "c"),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", colour: "g"),
  layers: (geom-point(size: 3pt),),
  scales: scales(
    x: scale-continuous(limits: (0, 4)),
    colour: scale-viridis-d(),
  ),
  width: 10cm,
  height: 6cm,
)

Scatter chart with three points coloured by group, the x axis pinned to a fixed domain and the colour scale set to a discrete viridis palette.

Scatter chart with three points coloured by group, the x axis pinned to a fixed domain and the colour scale set to a discrete viridis palette.

See also

plot, guides.

Back to top