rgb2col {jamba} | R Documentation |
Convert RGB color matrix to R color
Description
Convert RGB color matrix to R color
Usage
rgb2col(
red,
green = NULL,
blue = NULL,
alpha = NULL,
names = NULL,
maxColorValue = NULL,
keepNA = TRUE,
verbose = FALSE,
...
)
Arguments
red |
|
green |
|
blue |
|
alpha |
|
names |
|
maxColorValue |
|
keepNA |
|
verbose |
|
... |
Additional arguments are ignored. |
Details
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
isFALSE
then output colors will not have the alpha transparency, in hex form that means colors are in format"#RRGGBB"
and not"#RRGGBBAA"
.When
alpha
isTRUE
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]
, where0
is completely transparent, and1
is completely not transparent. Suppliedalpha
values will override those present inred
whenred
is a matrix like that produced fromgrDevices::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, useInf
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.
Value
character
vector of R colors.
See Also
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()
Examples
# 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));