hex: HEX color specification

View source: R/parse_hex.R

hexR Documentation

HEX color specification

Description

Converts colors specified as hexadecimal strings into R colors. This includes the usual format for R colors but also the shorter three letters format. In addition the # sign can be omitted.

Usage

hex(x)

Arguments

x

hexadecimal string specifying a color; named R or CSS color are also tolerated.

Details

Hexadecimal strings (hex for short) are how colors are usually represented in R. This function just brings a little more versatility in how those can be specified. Note, however, that R can use the 8 letter model to represent color with a transparency (alpha) component and that this function does not support it (and just removes the transparency).

Value

A vector of colors specified as hex codes

See Also

parse_color for the general function to parse colors in various specifications (which this function calls internally) and convert_color to convert parsed colors to another model.

Other color specifications: cmyk(), css(), hcl(), hsi(), hsl(), hsv(), lab(), parse_color(), rgb(), ryb(), temperature(), wavelength()

Other color specifications: cmyk(), css(), hcl(), hsi(), hsl(), hsv(), lab(), parse_color(), rgb(), ryb(), temperature(), wavelength()

Examples

hex("#ff3399")
hex("ff3399")
hex("ff3399")
hex("F39")
x <- c("#ff3399",       # hex specification valid in R
       "F39",           # hex specification not valid in R
       "whitesmoke",    # named color valid in R and CSS
       "darkorchid2",   # named R color (not existing in CSS)
       "rebeccapurple"  # named CSS color (not existing in R)
       )
hex(x)

(half_transparent <- alpha("#ff3399", 0.5))
hex(half_transparent)
# NB: the transparency portion (last two positions: '80') is removed

jiho/chroma documentation built on Nov. 26, 2022, 2:39 a.m.