scale-colour-discrete
Discrete colour scale mapping categorical levels to stroke colours.
Usage
scale-colour-discrete(
..args,
)Parameters
| Parameter | Default | Description |
|---|---|---|
..args |
Returns
Scale object consumed by plot.
Examples
Default palette mapping three categories to the library’s eight reserved discrete colours.
#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-discrete(),),
width: 10cm,
height: 6cm,
)Override palette with an explicit colour array to hand-pick the mapping order.
#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-discrete(palette: (
rgb("#1b9e77"), rgb("#d95f02"), rgb("#7570b3"),
)),),
width: 10cm,
height: 6cm,
)Bind a colour-blind-friendly palette to penguin species and reorder the legend via limits.
#plot(
data: penguins,
mapping: aes(x: "flipper-len", y: "body-mass", colour: "species"),
layers: (geom-point(size: 2pt, alpha: 0.85),),
scales: (scale-colour-discrete(
palette: (rgb("#0072B2"), rgb("#D55E00"), rgb("#009E73")),
limits: ("Adelie", "Chinstrap", "Gentoo"),
),),
labs: labs(x: "Flipper Length (mm)", y: "Body Mass (g)", colour: "Species"),
width: 11cm,
height: 6cm,
)See also
scale-colour-manual, scale-colour-viridis-d, scale-fill-discrete.