l_colorName | R Documentation |
Return the built-in color names by the given hex code.
l_colorName(color, error = TRUE, precise = FALSE)
color |
A vector of 12 digit (tcl) or 6 (8 with transparency) digit color hex code, e.g. "#FFFF00000000", "#FF0000" |
error |
Suppose the input is not a valid color, if |
precise |
Logical; When |
Function colors
returns the built-in color names
which R
knows about. To convert a hex code to a real color name,
we first convert these built-in colours and the hex code to RGB (red/green/blue) values
(e.g., "black" –> [0, 0, 0]). Then, using this RGB vector value,
the closest (Euclidean distance) built-in colour is determined.
Matching is "precise" whenever the minimum distance is zero;
otherwise it is "approximate",
locating the nearest R
colour.
A vector of built-in color names
l_hexcolor
, hex12tohex6
,
as_hex6color
l_colorName(c("#FFFF00000000", "#FF00FF", "blue"))
if(require(grid)) {
# redGradient is a matrix of 20 different colors
redGradient <- matrix(hcl(0, 80, seq(49, 68, 1)),
nrow=4, ncol=5, byrow = TRUE)
# a color plate
grid::grid.newpage()
grid::grid.raster(redGradient,
interpolate = FALSE)
# a "rough matching";
r <- l_colorName(redGradient)
# the color name of each row is identical...
r
grid::grid.newpage()
# very different from the first plate
grid::grid.raster(r, interpolate = FALSE)
# a "precise matching";
p <- l_colorName(redGradient, precise = TRUE)
# no built-in color names can be precisely matched...
p
}
## Not run:
# an error will be returned
l_colorName(c("foo", "bar", "red"))
# c("foo", "bar", "red") will be returned
l_colorName(c("foo", "bar", "#FFFF00000000"), error = FALSE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.