Skip to contents

R color to BRG (blue/green/red) conversion.

Usage

col2bgr(col, alpha = FALSE)

Arguments

col

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].

alpha

Logical value indicating whether the alpha channel (opacity) values should be returned.

Value

An integer matrix with three or four (for alpha = TRUE) rows and number of columns the length of col. If col has names these are used as the column names of the return value.

Details

NA (as integer or character) and "NA" mean transparent.

Values of col not of one of these types are coerced: real vectors are coerced to integer and other types to character. (factors are coerced to character: in all other cases the class is ignored when doing the coercion.)

Zero and negative values of col are an error.

See also

Author

Simon Garnier, garnier@njit.edu

Examples

col2bgr("red")
#>       [,1]
#> blue     0
#> green    0
#> red    255
col2bgr(1:10)
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> blue     0  107   79  230  229  188   16  158    0   107
#> green    0   83  208  151  226   11  199  158    0    83
#> red      0  223   97   34   40  205  245  158    0   223