Learn R Programming

plotrix (version 1.2-2)

rgb.to.hex: rgb.to.hex

Description

rgb.to.hex converts the first three values in rgb to a six digit hexadecimal string preceded by a hash character. If all three values are between 0 and 1, all are scaled up to a range of 0-255 unless scale.up is FALSE.

Usage

rgb.to.hex(rgb,scale.up=TRUE)

Arguments

rgb
A numeric vector of length at least 3 representing the relative red, green and blue values. Each value must be between 0 and 255.
scale.up
A logical value indicating whether to scale up when all values are between 0 and 1.

Value

  • hexadecimal color

authors

Jim Lemon

See Also

gradient.rect

Examples

Run this code
# a light purple color in a 0-1 format
 rgb.to.hex(c(0.9,0.5,0.9))
 # supressing the scaling gives almost pure black
 rgb.to.hex(c(0.9,0.5,0.9),FALSE)

Run the code above in your browser using DataLab