after-scale

Transform an aesthetic’s resolved value just before it reaches the geom’s draw step.

expr receives the channel’s scale-resolved value (or the channel default when the channel carries no source) and a context dict (theme, palette, trained, row, resolve-colour, …). The closure’s return value is what the geom finally draws. Currently honoured on colour, fill, alpha, size, linewidth, stroke, shape, and linetype. The closure runs once per row.

Usage

after-scale(
  expr,
)

Parameters

Parameter Default Description
expr Function (value, ctx) => any.

Returns

Late-binding marker consumed by aes.

Examples

Mirror the trained fill palette into the marker outline and darken it.

#let d = (
  (x: 1, y: 2, sp: "a"),
  (x: 2, y: 4, sp: "b"),
  (x: 3, y: 3, sp: "c"),
  (x: 4, y: 5, sp: "a"),
)
#plot(
  data: d,
  mapping: aes(
    x: "x", y: "y", fill: "sp",
    colour: after-scale((_, ctx) => {
      let trained = ctx.trained.at("fill", default: none)
      let v = ((ctx.resolve-colour)(trained, ctx.palette))(ctx.row.sp)
      v.darken(40%)
    }),
  ),
  layers: (geom-point(size: 5pt, stroke: 0.8pt),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of four points whose marker outline mirrors the fill palette darkened by 40 percent via after-scale.

Scatter chart of four points whose marker outline mirrors the fill palette darkened by 40 percent via after-scale.

See also

aes.

Back to top