Skip to contents

Converts a HSV color matrix to R hex color

Usage

hsv2col(hsvValue, ...)

Arguments

hsvValue

numeric HSV matrix, with rownames c("h","s","v") in any order, and optionally "alpha" rowname for alpha transparency.

...

additional arguments are ignored.

Value

character vector of R colors.

Details

This function augments the grDevices::hsv() function in that it handles output from grDevices::rgb2hsv() or col2hsv(), sufficient to run a series of conversion functions, e.g. hsv2col(col2hsv("red")). This function also maintains alpha transparency, which is not maintained by the grDevices::hsv() function.

Examples

# start with a color vector
# red and blue with partial transparency
colorV <- c("#FF000055", "#00339999");

# confirm the hsv matrix maintains transparency
col2hsv(colorV);
#>            [,1]      [,2]
#> h     0.0000000 0.6111111
#> s     1.0000000 1.0000000
#> v     1.0000000 0.6000000
#> alpha 0.3333333 0.6000000

# convert back to the original color
hsv2col(col2hsv(colorV));
#> [1] "#FF000055" "#00339999"