Convert color to hex

col2hex(color, alpha = 1)

Arguments

color

Character string. An R color or color as hex.

alpha

Transparency. A value from 0 to 1 (default).

Value

A character string of a hexadecimal color

Details

This function is primarily to be used on R colors, and will convert them to hexmode sufficient for typical use in visualization, web presentation, etc. If you already have a hex value, it can be useful for tacking on the alpha level.

See also

Examples

library(visibly) col2hex('red')
#> [1] "#FF0000FF"
col2hex('#ff5500', alpha = .1)
#> [1] "#FF55001A"