Skip to contents

Extract multiple color components at the same time.

Usage

clr_extract(
  col,
  components = c("red", "green", "blue", "hue_hsl", "saturation", "lightness", "hue_hcl",
    "chroma", "luminance")
)

Arguments

col

A colors object (see color()) or a vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by grDevices::colors()), a hexadecimal string (see col2rgb()), or a positive integer i meaning grDevices::palette()[i].

components

A character vector of components that should be extracted. See Details for allowed components.

Value

A data.frame of components.

Details

The allowed values for components are:

  • red

  • green

  • blue

  • hue_hsl

  • saturation

  • lightness

  • hue_hcl

  • chroma

  • luminance

clr_extract() is to be preferred over other extraction functions if you need to extract multiple components at the same time, since it doesn't repeat transformations.

See also

Examples

clr_extract(rainbow(10))
#>    red green blue hue_hsl saturation lightness   hue_hcl    chroma luminance
#> 1  255     0    0       0        100        50  12.17440 179.04898  53.24079
#> 2  255   153    0      36        100        50  39.43336 109.91317  72.26072
#> 3  204   255    0      72        100        50 102.90030 109.55103  93.60533
#> 4   51   255    0     108        100        50 126.51692 133.56456  88.07403
#> 5    0   255  102     144        100        50 132.96726 118.64503  88.19634
#> 6    0   255  255     180        100        50 192.17223  72.08567  91.11322
#> 7    0   102  255     216        100        50 259.85834 127.32690  47.90478
#> 8   51     0  255     252        100        50 267.23002 132.04551  33.81896
#> 9  204     0  255     288        100        50 291.98078 133.06697  51.90416
#> 10 255     0  153     324        100        50 346.98829 133.88359  55.65103

clr_extract(rainbow(10), c("hue_hsl", "saturation"))
#>    hue_hsl saturation
#> 1        0        100
#> 2       36        100
#> 3       72        100
#> 4      108        100
#> 5      144        100
#> 6      180        100
#> 7      216        100
#> 8      252        100
#> 9      288        100
#> 10     324        100