scale-fill-discrete
Discrete fill scale mapping categorical levels to fill colours.
Usage
scale-fill-discrete(
..args,
)Parameters
| Parameter | Default | Description |
|---|---|---|
..args |
Returns
Scale object consumed by plot.
Examples
Default palette filling three bars from the library’s reserved discrete colours.
#let d = (
(grp: "a", y: 1),
(grp: "b", y: 2),
(grp: "c", y: 3),
)
#plot(
data: d,
mapping: aes(x: "grp", y: "y", fill: "grp"),
layers: (geom-col(),),
scales: (scale-fill-discrete(),),
width: 10cm,
height: 6cm,
)The palette laid out as a swatch strip via geom-rect, one rectangle per level.
#let levels = ("a", "b", "c", "d", "e", "f", "g", "h")
#let d = levels.enumerate().map(((i, k)) => (
xmin: i, xmax: i + 1, ymin: 0, ymax: 1, k: k,
))
#plot(
data: d,
mapping: aes(xmin: "xmin", xmax: "xmax", ymin: "ymin", ymax: "ymax", fill: "k"),
layers: (geom-rect(),),
scales: (scale-fill-discrete(),),
guides: guides(fill: guide-none()),
width: 8cm,
height: 1cm,
)See also
scale-fill-manual, scale-fill-viridis-d, scale-colour-discrete.