Package 'palettecore'

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 with CIEDE2000 spacing, and audits every palette under simulated colour-vision deficiency, greyscale conversion, sRGB gamut and 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.2.2
Built: 2026-07-23 22:40:30 UTC
Source: https://github.com/heidihelena/palettecore

Help Index


CIEDE2000 colour difference between two sRGB colours

Description

Computed via CIELAB under D65 (Sharma et al. 2005 formulation).

Usage

ciede2000(rgb1, rgb2)

Arguments

rgb1, rgb2

Numeric vectors of length 3, sRGB channels in [0, 1].

Value

CIEDE2000 distance (0 for identical colours, about 100 for black vs white).


WCAG 2.x contrast ratio between two sRGB colours

Description

WCAG 2.x contrast ratio between two sRGB colours

Usage

contrast_ratio(rgb1, rgb2)

Arguments

rgb1, rgb2

Numeric vectors of length 3, sRGB channels in [0, 1].

Value

Contrast ratio between 1 and 21.


Generate an audited palette from one seed colour

Description

Generate an audited palette from one seed colour

Usage

generate_palette(
  seed,
  n = 8L,
  kind = "sequential",
  background = "#FFFFFF",
  use = "data_fill",
  thresholds = NULL,
  anchor = "path"
)

Arguments

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).

Value

List with hexes, diagnostics and warnings.

Examples

r <- generate_palette("#8B6FC9", n = 4, kind = "sequential")
r$hexes
r$warnings

Convert a HEX colour to OKLCH

Description

Convert a HEX colour to OKLCH

Usage

hex_to_oklch(hex_str)

Arguments

hex_str

Colour as HEX string.

Value

Numeric vector c(L, C, H): OKLab lightness, chroma, hue in degrees.


Convert a HEX colour to sRGB

Description

Convert a HEX colour to sRGB

Usage

hex_to_srgb(hex_str)

Arguments

hex_str

Colour as HEX string, e.g. "#8B6FC9" (3- or 6-digit).

Value

Numeric vector of length 3, sRGB channels in [0, 1].


Largest OKLCH chroma at (L, H) inside the sRGB gamut

Description

Binary search; matches the Python reference implementation.

Usage

max_chroma(L, H, c_hi = 0.4, tol = 1e-04)

Arguments

L

OKLab lightness in [0, 1].

H

OKLCH hue in degrees.

c_hi

Upper search bound for chroma.

tol

Search tolerance.

Value

Maximum displayable chroma (0 if (L, H) itself is out of gamut).


Convert an OKLCH colour to HEX

Description

Convert an OKLCH colour to HEX

Usage

oklch_to_hex(lch)

Arguments

lch

Numeric vector c(L, C, H).

Value

HEX string (sRGB, channel values clipped to [0, 1]).


Pre-clamp gamut excursion of a CVD simulation

Description

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.

Usage

out_of_gamut_excursion(rgb, condition)

Arguments

rgb

Numeric vector of length 3, sRGB channels in [0, 1].

condition

One of "protanopia", "deuteranopia", "tritanopia".

Value

Non-negative excursion magnitude in linear RGB.


Discrete colour scale from an audited palettecore palette

Description

Generates the palette with generate_palette() and surfaces its audit warnings via warning(), so an inaccessible combination never passes silently into a figure.

Usage

scale_colour_accessible(seed, kind = "categorical", ...)

scale_color_accessible(seed, kind = "categorical", ...)

Arguments

seed

Seed colour as HEX.

kind

Palette kind; "categorical" is the usual choice for discrete scales.

...

Passed to generate_palette() (background, use, thresholds, ...).


Discrete fill scale from an audited palettecore palette

Description

Discrete fill scale from an audited palettecore palette

Usage

scale_fill_accessible(seed, kind = "categorical", ...)

Arguments

seed

Seed colour as HEX.

kind

Palette kind; "categorical" is the usual choice for discrete scales.

...

Passed to generate_palette() (background, use, thresholds, ...).


Simulate colour-vision deficiency (complete dichromacy)

Description

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.

Usage

simulate_cvd(rgb, condition)

Arguments

rgb

Numeric vector of length 3, sRGB channels in [0, 1].

condition

One of "protanopia", "deuteranopia", "tritanopia".

Value

Simulated sRGB colour, clamped to [0, 1].


Convert an sRGB colour to HEX

Description

Convert an sRGB colour to HEX

Usage

srgb_to_hex(rgb)

Arguments

rgb

Numeric vector of length 3, sRGB channels in [0, 1].

Value

HEX string, e.g. "#8B6FC9".