Skip to contents

Extract the red, green, or blue color components from a vector of colors.

Usage

clr_extract_red(col)

clr_extract_green(col)

clr_extract_blue(col)

clr_extract_alpha(col)

Arguments

col

a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i].

Value

Numeric vector of values.

Details

The values of the output will range between 0 and 255.

Use [clr_extract()] if you are planning to extraction multiple components.

See also

Examples

clr_extract_red(rainbow(100))
#>   [1] 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 250
#>  [19] 235 219 204 189 173 158 143 128 112  97  82  66  51  36  20   5   0   0
#>  [37]   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
#>  [55]   0   0   0   0   0   0   0   0   0   0   0   0   0   5  20  36  51  66
#>  [73]  82  97 112 128 143 158 173 189 204 219 235 250 255 255 255 255 255 255
#>  [91] 255 255 255 255 255 255 255 255 255 255
clr_extract_green(rainbow(100))
#>   [1]   0  15  31  46  61  77  92 107 122 138 153 168 184 199 214 229 245 255
#>  [19] 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
#>  [37] 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 240 224 209
#>  [55] 194 178 163 148 133 117 102  87  71  56  41  25  10   0   0   0   0   0
#>  [73]   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
#>  [91]   0   0   0   0   0   0   0   0   0   0
clr_extract_blue(rainbow(100))
#>   [1]   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
#>  [19]   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0  10  26
#>  [37]  41  56  71  87 102 117 133 148 163 179 194 209 224 240 255 255 255 255
#>  [55] 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
#>  [73] 255 255 255 255 255 255 255 255 255 255 255 255 245 230 214 199 184 168
#>  [91] 153 138 122 107  92  76  61  46  31  15
clr_extract_alpha(rainbow(100))
#>   [1] 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
#>  [19] 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
#>  [37] 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
#>  [55] 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
#>  [73] 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
#>  [91] 255 255 255 255 255 255 255 255 255 255