closestRcolor | R Documentation |
Find the closest R color for a vector of colors
closestRcolor(
x,
colorSet = colors(),
Cgrey = getOption("jam.Cgrey", 5),
C_min = Cgrey,
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,
...
)
closest_named_color(
x,
colorSet = colorjam::named_colors,
Cgrey = getOption("jam.Cgrey", 5),
C_min = Cgrey,
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,
...
)
x |
character vector of colors, either in hex format or any valid color in R. |
colorSet |
|
Cgrey , C_min |
Rules:
|
showPalette |
|
colorModel |
|
Hwt , Cwt , Lwt |
|
warpHue |
|
preset |
|
method |
|
returnType |
|
verbose |
|
This function is intended as a relatively efficient method to compare
a set of colors to the named R colors provided by grDevices::colors()
.
Color matching provides substantial improvements over similar functions from other R packages. Notably, colors are matched using either HCL or LUB color model by default, both of which provide vast improvement over RGB color matching, due to better spacing of colors, and increased resolution of color hue.
For colorModel="HCL"
the coordinates are weighted to prioritize
matching color Hue above Chroma and Luminance. The distance method
by default uses method="maximum"
which also emphasizes the lowest
distance in any of the three dimensions.
Notably, this function does not use color_distance()
, in part
because in practice the color metrics used by 'cie2000', 'cie94', 'cmc'
did not prioritize the same color hue, and often the returned color
was similar but not the most visibly similar in terms of hue.
Also color_distance()
does not currently permit weights for Hue,
Chroma, Luminance, as these values are already defined in
farver::compare_colour()
.
Consider testing then adding color_distance()
as an optional metric.
Test whether it could improve results.
character
vector of colors, optionally customized
by argument returnType
.
Other colorjam core:
blend_colors()
,
color_complement()
,
colors_to_df()
,
group2colors()
,
rainbowJam()
,
sort_colors()
,
subset_colors()
closestRcolor(rainbowJam(12), showPalette=TRUE);
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.