DescTools (version 0.99.14)

ColToHex: Convert a Color into Hex String

Description

Convert a color given by name, by its palette index or by rgb-values into a string of the form "#rrggbb" or "#rrggbbaa".

Usage

ColToHex(col, alpha = 1)

Arguments

col
vector of any of either a color name (an element of colors()), or an integer i meaning palette()[i]. Non-string values are coerced to integer.
alpha
the alpha value to be used. This can be any value from 0 (fully transparent) to 1 (opaque). Default is 1.

Value

  • Returns the colorvalue in #rrggbb" or #rrggbbaa" format. (character)

See Also

HexToCol, ColToRgb, colors

Examples

Run this code
ColToHex(c("lightblue", "salmon"))

x <- ColToRgb("darkmagenta")
x[2,] <- x[2,] + 155
RgbToCol(x)

Run the code above in your browser using DataCamp Workspace