This functions converts color-class objects into hexadecimal strings.

hex(from, gamma = NULL, fixup = FALSE)

Arguments

from

The color object to be converted.

gamma

Deprecated.

fixup

Should the color be corrected to a valid RGB value before correction. The default is to convert out-of-gamut colors to the string "NA".

Value

A vector of character strings.

Details

The color objects are first converted to sRGB color objects. They are then multiplied by 255 and rounded to obtain an integer value. These values are then converted to hexadecimal strings of the form "#RRGGBB" and suitable for use as color descriptions for R graphics. Out of gamut values are either corrected to valid RGB values by translating the the individual primary values so that they lie between 0 and 255.

See also

Author

Ross Ihaka

Examples

hsv <- HSV(seq(0, 360, length.out = 7)[-7], 1, 1)
hsv
#>        H S V
#> [1,]   0 1 1
#> [2,]  60 1 1
#> [3,] 120 1 1
#> [4,] 180 1 1
#> [5,] 240 1 1
#> [6,] 300 1 1
hex(hsv)
#> [1] "#FF0000" "#FFFF00" "#00FF00" "#00FFFF" "#0000FF" "#FF00FF"
barplot(rep(1,6), col = hex(hsv))