scale-colour-brewer
Discrete ColorBrewer colour scale.
palette selects a named ColorBrewer palette such as "Set1", "Dark2", or "Spectral". Categorical levels are mapped to colours in the order they first appear in the data.
Usage
scale-colour-brewer(
palette,
name,
limits,
oob,
labels,
)Parameters
| Parameter | Default | Description |
|---|---|---|
palette |
ColorBrewer palette name (qualitative, sequential, or diverging). | |
name |
Legend title. Overrides any name set via labels when both are present. |
|
limits |
Array of level names controlling order and inclusion, or none. |
|
oob |
Out-of-range policy: "drop" (default) removes rows whose value falls outside limits; "squish" clamps continuous values to the nearest endpoint. |
|
labels |
Array of legend labels aligned with limits, or auto. |
Returns
Scale object consumed by plot.
Examples
Set1 palette mapping three categorical levels to bold qualitative hues.
#let d = (
(x: 1, y: 2, sp: "a"),
(x: 2, y: 4, sp: "b"),
(x: 3, y: 3, sp: "c"),
)
#plot(
data: d,
mapping: aes(x: "x", y: "y", colour: "sp"),
layers: (geom-point(size: 3pt),),
scales: (scale-colour-brewer(palette: "Set1"),),
width: 10cm,
height: 6cm,
)Switching to the diverging Spectral palette suits ordered categories with a meaningful midpoint.
#let d = (
(x: 1, y: 2, sp: "low"),
(x: 2, y: 3, sp: "mid"),
(x: 3, y: 4, sp: "high"),
)
#plot(
data: d,
mapping: aes(x: "x", y: "y", colour: "sp"),
layers: (geom-point(size: 3pt),),
scales: (scale-colour-brewer(
palette: "Spectral",
limits: ("low", "mid", "high"),
),),
width: 10cm,
height: 6cm,
)