| classbound_palette | R Documentation |
Returns a named character vector mapping class labels to hex color codes. Colors are assigned deterministically: class labels are sorted alphabetically before assignment, so the same class always receives the same color regardless of the order the classes are supplied.
classbound_palette(classes)
classes |
A character vector or factor containing class labels. Duplicates
and |
The first 20 classes are assigned colors from a curated palette of visually
distinct hues designed for use on both light and dark backgrounds. For more than
20 classes, additional colors are generated using the golden-angle method
(hue = (index * phi) %% 1 where phi = 0.618...), which produces perceptually
distinct colors with uniform spacing in HCL space.
plot_boundary() uses this palette by default. If an RColorBrewer palette is
requested via palette = but cannot accommodate the number of classes (e.g.,
"Dark2" supports a maximum of 8), it automatically falls back to
classbound_palette().
A named character vector where names are the unique sorted class labels
and values are hex color codes (e.g., "#E6194B").
plot_boundary()
# 3-class palette
classbound_palette(c("Adelie", "Chinstrap", "Gentoo"))
# Colors are alphabetically ordered, so order of input doesn't matter
identical(
classbound_palette(c("B", "A", "C")),
classbound_palette(c("C", "A", "B"))
)
# Use in plot_boundary() via the palette argument
library(palmerpenguins)
data(penguins)
peng_data <- na.omit(penguins[, c("species", "bill_length_mm", "bill_depth_mm")])
m <- fit_model(peng_data, species ~ ., rpart::rpart)
m <- boundary_compute(m, resolution = 50)
plot_boundary(m,
obs_data = peng_data, x_col = "bill_length_mm",
y_col = "bill_depth_mm", true_label = "species"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.