col2hexStr: Convert color to Hex string

Description Usage Arguments Details Value See Also Examples

View source: R/strings.R

Description

Convert color to Hex string

Usage

1
col2hexStr(col, alpha = NULL, prefix = "#", ...)

Arguments

col

character or integer indicating color

alpha

NULL or numeric, transparency. See grDevices::rgb

prefix

character, default is "#"

...

passing to adjustcolor

Details

col2hexStr converts colors such as 1, 2, 3, "red", "blue", ... into hex strings that can be easily recognized by 'HTML', 'CSS' and 'JavaScript'. Internally this function uses adjustcolor with two differences:

  1. the returned hex string does not contain alpha value if alpha is NULL;

  2. the leading prefix "#" can be customized

Value

characters containing the hex value of each color. See details

See Also

adjustcolor

Examples

1
2
3
4
5
6
col2hexStr(1, prefix = '0x')      # "0x000000"
col2hexStr('blue')                # "#0000FF"

# Change default palette, see "grDevices::colors()"
grDevices::palette(c('orange3', 'skyblue1'))
col2hexStr(1)                     # Instead of #000000, #CD8500

dipsaus documentation built on Sept. 6, 2021, 5:08 p.m.