Skip to contents

Convert colors to data.frame of color attributes

Usage

colors_to_df(x, ..., alpha = TRUE, byCols = NULL)

Arguments

x

character vector of R colors

...

any valid criteria to subset the color data.frame.

alpha

logical indicating whether to retain alpha transparency in intermediate operations. When alpha=FALSE then all color transparency is ignored, and colors will be returned with no transparency.

byCols

character vector of colnames to sort after the subset operation.

Value

data.frame with color attributes as columns. When byCols is defined, the data.frame is sorted using jamba::mixedSortDF(). When ... is supplied, subset() is applied to subset colors.

Details

This function takes a vector of colors and returns a data.frame with relevant color attributes:

  • "num" contains the integer index of the input vector x.

  • "hex" contains character values with hexadecimal colors including alpha. If the input x is "red" then the hex value will be converted to "#FF0000FF".

  • "name" if names(x) is not empty

Added by jamba::col2hcl()

  • "H" contains color hue as values from 0 to 360.

  • "C" contains color chroma (aka saturation) ranging from 0 up to 200, where typical "full saturation" is represented as values above 100.

  • "L" contains color luminance (brightness/lightness) ranging from 0 to 100.

  • "alpha" the alpha transparency, ranging from 0 (fully transparent) to 1 (fully opaque, not transparent).

Added by grDevices::col2rgb()

  • "red" contains the red color channel, values range from 0 to 255.

  • "green" contains the green color channel, values range from 0 to 255.

  • "blue" contains the blue color channel, values range from 0 to 255.

Added by jamba::col2hsv()

  • "h" contains color hue as values from 0 to 1. Note these values may not map directly to color hue obtained from jamba::col2hcl().

  • "s" contains color saturation with values from 0 to 1.

  • "v" contains color vibrance (brightness/lightness) with values from 0 to 1.

Added by jamba::col2hsl()

  • "hsl_h" contains color hue as values from 0 to 1. Note these values may not map directly to color hue obtained from jamba::col2hcl().

  • "hsl_s" contains color saturation with values from 0 to 100.

  • "hsl_l" contains color luminance (brightness/lightness) with values from 0 to 100.

See also