color_distance: Calculate color distance between two or more colors

color_distanceR Documentation

Calculate color distance between two or more colors

Description

Calculate color distance between two or more colors

Usage

color_distance(
  x,
  y = NULL,
  method = c("cie2000", "cie94", "cie1976", "cmc", "euclidean"),
  use_white = "F5",
  do_plot = FALSE,
  ...
)

Arguments

x

character color, required input colors.

  • When y is supplied, values in y are recycled to length(x), and each entry in x is directly compared to y.

  • When y is not supplied, x is compared to itself, returning a matrix.

y

character color, default NULL

method

character, default 'cie2000', the color distance method, passed to farver::compare_colour(). In future, this argument may permit additional distance methods, and/or specific color function, in order to impose other criteria and adjustments.

use_white

character default "F5" representing the white reference, any value recognized by farver::as_white_ref().

  • The default 'F5' represents 'daylight fluorescent' and in qualitative testing was most effective when defining color distances.

  • The typical default 'D65' is 'daylight 6500K' and is typically used for neutral daylight without blue (cool) or yellow (warm) shifted background lighting.

...

additional arguments are passed to farver::compare_colour()

Details

Color distance is calculated using farver::compare_colour(), with some defaults intended in future to assist with color blindness calculations.

Value

numeric color distance with length(x) entries when both x and y are supplied, or a numeric matrix with color distances between all entries in x.

  • An attribute 'method' is added with the color distance used, mainly so the method can be used by show_color_distance(), but also by other methods as relevant.

Examples

color_distance("red", "firebrick", use_white="D65")

color_distance(grDevices::palette.colors(15))

pc <- rainbowJam(5)
cd <- color_distance(pc);
show_color_distance(cd, pc=pc, column_title="rainbowJam()");

pc <- grDevices::palette.colors(15);
cd <- color_distance(pc);
show_color_distance(cd, pc=pc, column_title="palette.colors()");


jmw86069/colorjam documentation built on June 10, 2025, 12:02 p.m.