rgb2col | R Documentation |
Convert RGB color matrix to R color
rgb2col(
red,
green = NULL,
blue = NULL,
alpha = NULL,
names = NULL,
maxColorValue = NULL,
keepNA = TRUE,
verbose = FALSE,
...
)
red |
|
green |
|
blue |
|
alpha |
|
names |
|
maxColorValue |
|
keepNA |
|
verbose |
|
... |
Additional arguments are ignored. |
This function intends to augment the rgb
function, which
does not handle output from col2rgb
. The goal is to handle
multiple color conversions, e.g. rgb2col(grDevices::col2rgb("red"))
. This
function also maintains alpha transparency when supplied.
The output is named either by names(red), rownames(red), or if supplied,
the value of the parameter names
.
Note that alpha
is used to define alpha transparency, but has
additional control over the output.
When alpha
is FALSE
then
output colors will not have the alpha transparency, in hex form that
means colors are in format "#RRGGBB"
and not "#RRGGBBAA"
.
When alpha
is TRUE
the previous alpha transparency values are
used without change.
When alpha
is a numeric vector, numeric values are always
expected to be in range [0,1]
, where 0
is completely transparent,
and 1
is completely not transparent. Supplied alpha
values will
override those present in red
when red
is a matrix like that
produced from grDevices::col2rgb(..., alpha=TRUE)
.
When alpha
is a numeric vector, use -1
or any negative number
to indicate the alpha value should be removed.
When alpha
is a numeric vector, use Inf
to indicate the alpha
transparency should be retained without change.
Therefore, alpha = c(-1, 0, 1, Inf)
will apply the following,
in order: remove alpha; set alpha to 0; set alpha to 1; set alpha
to the same as the input color.
character
vector of R colors.
Other jam color functions:
alpha2col()
,
applyCLrange()
,
col2alpha()
,
col2hcl()
,
col2hsl()
,
col2hsv()
,
color2gradient()
,
fixYellow()
,
fixYellowHue()
,
getColorRamp()
,
hcl2col()
,
hsl2col()
,
hsv2col()
,
isColor()
,
kable_coloring()
,
makeColorDarker()
,
rainbow2()
,
setCLranges()
,
setTextContrastColor()
,
showColors()
,
unalpha()
,
warpRamp()
# start with a color vector
# red and blue with partial transparency
colorV <- c("#FF000055", "#00339999");
# Show the output of rgb2col
# make sure to include alpha=TRUE to maintain alpha transparency
grDevices::col2rgb(colorV, alpha=TRUE);
# confirm we can convert from RGB back to the same colors
rgb2col(grDevices::col2rgb(colorV, alpha=TRUE));
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.