| Title: | Derive, Optimise and Audit a Scientific Colour Palette from One Seed Colour |
|---|---|
| Description: | Generates sequential, diverging and categorical colour palettes from a single seed colour in OKLCH (the cylindrical lightness-chroma-hue representation of the Oklab perceptual colour space), with spacing measured by the CIEDE2000 colour-difference formula of the International Commission on Illumination. Audits every palette under simulated colour-vision deficiency, greyscale conversion, the standard Red Green Blue (sRGB) gamut and Web Content Accessibility Guidelines (WCAG) contrast. Colour-vision deficiency is simulated at severity 1.0 with the model of Machado, Oliveira and Fernandes (2009) <doi:10.1109/TVCG.2009.113>; the design rationale follows Crameri, Shephard and Heron (2020) <doi:10.1038/s41467-020-19160-7>. Mirrors the 'Python' reference implementation maintained in the same repository and is validated against shared parity fixtures. Thresholds are configurable design rules, not established accessibility cut-offs. |
| Authors: | Heidi Helena Andersén [aut, cre] (ORCID: <https://orcid.org/0000-0001-5923-5865>) |
| Maintainer: | Heidi Helena Andersén <[email protected]> |
| License: | Apache License (>= 2) |
| Version: | 0.4.1 |
| Built: | 2026-10-08 10:39:36 UTC |
| Source: | https://github.com/cran/palettecore |
Computed via CIELAB under D65 (Sharma et al. 2005 formulation).
ciede2000(rgb1, rgb2)ciede2000(rgb1, rgb2)
rgb1, rgb2
|
Numeric vectors of length 3, sRGB channels in [0, 1]. |
CIEDE2000 distance (0 for identical colours, about 100 for black vs white).
WCAG 2.x contrast ratio between two sRGB colours
contrast_ratio(rgb1, rgb2)contrast_ratio(rgb1, rgb2)
rgb1, rgb2
|
Numeric vectors of length 3, sRGB channels in [0, 1]. |
Contrast ratio between 1 and 21.
Generate an audited palette from one seed colour
generate_palette( seed, n = 8L, kind = "sequential", background = "#FFFFFF", use = "data_fill", thresholds = NULL, anchor = "path", vividness = 0, rotations = 1 )generate_palette( seed, n = 8L, kind = "sequential", background = "#FFFFFF", use = "data_fill", thresholds = NULL, anchor = "path", vividness = 0, rotations = 1 )
seed |
Seed colour as HEX, e.g. "#8B6FC9". |
n |
Number of colours (2-24). |
kind |
"sequential", "diverging" or "categorical". |
background |
Intended background as HEX. |
use |
"data_fill", "text", "line" or "UI". |
thresholds |
Named list overriding the default dE floors. |
anchor |
"path" or "exact" (categorical always contains the seed). |
vividness |
0.0 (default, seed-faithful) to 1.0 (chroma pushed toward the gamut edge). Lifts chroma only, never lightness, on every kind; the default reproduces earlier versions exactly. |
rotations |
Helix only: how many full hue turns the cubehelix makes over its lightness range (fractional or negative allowed). Rejected if non-default for other kinds. |
List with hexes, diagnostics and warnings.
r <- generate_palette("#8B6FC9", n = 4, kind = "sequential") r$hexes r$warningsr <- generate_palette("#8B6FC9", n = 4, kind = "sequential") r$hexes r$warnings
Convert a HEX colour to OKLCH
hex_to_oklch(hex_str)hex_to_oklch(hex_str)
hex_str |
Colour as HEX string. |
Numeric vector c(L, C, H): OKLab lightness, chroma, hue in degrees.
Convert a HEX colour to sRGB
hex_to_srgb(hex_str)hex_to_srgb(hex_str)
hex_str |
Colour as HEX string, e.g. "#8B6FC9" (3- or 6-digit). |
Numeric vector of length 3, sRGB channels in [0, 1].
Binary search; matches the Python reference implementation.
max_chroma(L, H, c_hi = 0.4, tol = 1e-04)max_chroma(L, H, c_hi = 0.4, tol = 1e-04)
L |
OKLab lightness in [0, 1]. |
H |
OKLCH hue in degrees. |
c_hi |
Upper search bound for chroma. |
tol |
Search tolerance. |
Maximum displayable chroma (0 if (L, H) itself is out of gamut).
Convert an OKLCH colour to HEX
oklch_to_hex(lch)oklch_to_hex(lch)
lch |
Numeric vector c(L, C, H). |
HEX string (sRGB, channel values clipped to [0, 1]).
Largest linear-RGB excursion outside [0, 1] before clamping. 0 means the simulated colour was displayable as-is; larger values mean clamping altered the colour and measured separations involving it should be read with that in mind.
out_of_gamut_excursion(rgb, condition)out_of_gamut_excursion(rgb, condition)
rgb |
Numeric vector of length 3, sRGB channels in [0, 1]. |
condition |
One of "protanopia", "deuteranopia", "tritanopia". |
Non-negative excursion magnitude in linear RGB.
Generates the palette with generate_palette() and surfaces its audit warnings via warning(), so an inaccessible combination never passes silently into a figure.
scale_colour_accessible(seed, kind = "categorical", ...) scale_color_accessible(seed, kind = "categorical", ...)scale_colour_accessible(seed, kind = "categorical", ...) scale_color_accessible(seed, kind = "categorical", ...)
seed |
Seed colour as HEX. |
kind |
Palette kind; "categorical" is the usual choice for discrete scales. |
... |
Passed to generate_palette() (background, use, thresholds, ...). |
A ggplot2 discrete scale object (class ScaleDiscrete, a ggproto
object) for the colour aesthetic, to be added to a ggplot with +.
When the plot is built, the scale generates an audited palette of hex
colours for the number of levels in the data and emits any audit
warnings (colour-vision deficiency, greyscale, gamut or contrast
failures) via warning().
Generates the palette with generate_palette() and surfaces its audit warnings via warning(), so an inaccessible combination never passes silently into a figure.
scale_fill_accessible(seed, kind = "categorical", ...)scale_fill_accessible(seed, kind = "categorical", ...)
seed |
Seed colour as HEX. |
kind |
Palette kind; "categorical" is the usual choice for discrete scales. |
... |
Passed to generate_palette() (background, use, thresholds, ...). |
A ggplot2 discrete scale object (class ScaleDiscrete, a ggproto
object) for the fill aesthetic, to be added to a ggplot with +.
When the plot is built, the scale generates an audited palette of hex
colours for the number of levels in the data and emits any audit
warnings (colour-vision deficiency, greyscale, gamut or contrast
failures) via warning().
Machado et al. (2009) matrices at severity 1.0 on the paper's [0, 1] scale, applied in linear RGB and clamped to the displayable range.
simulate_cvd(rgb, condition)simulate_cvd(rgb, condition)
rgb |
Numeric vector of length 3, sRGB channels in [0, 1]. |
condition |
One of "protanopia", "deuteranopia", "tritanopia". |
Simulated sRGB colour, clamped to [0, 1].
Convert an sRGB colour to HEX
srgb_to_hex(rgb)srgb_to_hex(rgb)
rgb |
Numeric vector of length 3, sRGB channels in [0, 1]. |
HEX string, e.g. "#8B6FC9".