Closest colorjam named_colors for a vector of colors
Usage
closest_named_color(
x,
colorSet = colorjam::named_colors,
C_min = Cgrey,
Cgrey = getOption("jam.Cgrey", 5),
showPalette = FALSE,
colorModel = c("hcl", "LUV"),
Hwt = 2.5,
Cwt = 1,
Lwt = 4,
warpHue = TRUE,
preset = "ryb",
method = "maximum",
returnType = c("color", "name", "match"),
verbose = FALSE,
...
)
Arguments
- x
character vector of colors, either in hex format or any valid color in R.
- colorSet
character
vector of colors, by defaultnamed_colors
with provides 4,447 total hex colors, each with human-assigned color name. These colors also include hex colors from Rcolors()
which were not already included in the reference colors.- C_min, Cgrey
numeric
minimum color Chroma filter applied to handle greyscale colors. In most practical casesC_min
andCgrey
should be the same value. NoteCgrey
is used as an option injamba::make_styles()
,jamba::applyCLrange()
for similar use cases, so it is used here as well:getOption("jamba.Cgrey", 5)
.C_min
is applied tocolorSet
to require the closest matching color to have at least this color Chroma (saturation).Cgrey
is applied tox
to determine if the input color itself is considered greyscale, in which case it should not be matched with saturated colors since there is no reliable color hue. Instead, the subset ofcolorSet
with Chroma belowC_min
is used for color-matching.
Reworded in short:
Colors in
x
with Chroma aboveCgrey
are matched with colors incolorSet
with Chroma aboveC_min
.Colors in
x
with Chroma belowCgrey
are matched with colors incolorSet
with Chroma belowC_min
.The end result should be that saturated input colors match saturated reference colors, and unsaturated input colors match unsaturated reference colors.
- showPalette
logical
indicating whether to display the input colors and resulting closest matching colors by usingjamba::showColors()
.- colorModel
character
color model to use:"hcl"
: default, uses HCL provided byjamba::col2hcl()
which uses the equivalent ofcolorspace::polarLUV()
and considers color hues in terms of 360 degree angles along a color wheel."LUV"
: uses CIELUV color space, provided bycolorspace::LUV()
which encodes the angular color hue in 3-D Cartesian space, allowing comparisons using Euclidean distance.
- Hwt, Cwt, Lwt
numeric
relative weights for each dimension of HCL colors, for the H, C, and L channels, respectively.- warpHue
logical
indicating whether to perform the hue warp operation usingh2hw()
which improves the ability to match colors between orange and green.- preset
character
string to define the color wheel used when matching input colorsx
to colors incolorSet
. This preset is used withh2hw()
andhw2h()
. The defaultpreset="ryb"
allows greatest distinction in colors without imposing additional restrictions such as bypreset="dichromat"
which would only match color-safe colors. The purpose here is to identify and label colors based upon a reference set of colors.- method
character
string passed tostats::dist()
. The defaultmethod="maximum"
works well forcolorModel="hcl"
, and assigns distance using the largest distance across the three color coordinates H, C, and L. It requires the best overall match across all three coordinates rather than any weighted combination of coordinate distances. Other methods in testing allowed matches of different color hues when luminance and chroma values were very similar. WithcolorModel="LUV"
we recommend usingmethod="euclidean"
, which seems to work well with projected color coordinates L, U, and V. The U, and V coordinates are roughly the angular color hue projected into a flat plane, the L describing Luminance.- returnType
character
type of data to return:"color"
returns the color values incolorSet
, which by default are color names fromgrDevices::colors()
"name"
returnsnames(colorSet)
if they exist, otherwise values fromcolorSet
"match"
returns an integer vector as an index tocolorSet
- verbose
logical
whether to print verbose output.
See also
Other colorjam core:
blend_colors()
,
closestRcolor()
,
color_complement()
,
colors_to_df()
,
group2colors()
,
rainbowJam()
,
sort_colors()
,
subset_colors()