Create a matrix from vector to represent colors in gradient
gradient(x, min.color, max.color, alpha = NULL, use.names = TRUE, na.rm = TRUE)
a numeric vector.
color of minimum value.
color of maximum value.
logical of whether to include alpha channel. NULL
to let the function decide by input.
logical of whether to preserve names of input vector.
logical indicating whether to ignore missing values as x
is normalized. (defult is TRUE
)
a matrix with rgba columns in which each row corresponds to the rgba
value (0-255) of each element in input vector x
. Use csscolor
to convert the matrix to css color strings compatible with web browsers.
gradient(c(1,2,3,4,5), "white", "red")
#> [,1] [,2] [,3] [,4] [,5]
#> red 255 255 255 255 255
#> green 255 191 127 63 0
#> blue 255 191 127 63 0
gradient(c(5,4,3,2,1), "white", "red")
#> [,1] [,2] [,3] [,4] [,5]
#> red 255 255 255 255 255
#> green 0 63 127 191 255
#> blue 0 63 127 191 255
gradient(c(1,3,2,4,5), "white", "red")
#> [,1] [,2] [,3] [,4] [,5]
#> red 255 255 255 255 255
#> green 255 127 191 63 0
#> blue 255 127 191 63 0
gradient(c(1,3,2,4,5), rgb(0,0,0,0.5), rgb(0,0,0,1), alpha = TRUE)
#> [,1] [,2] [,3] [,4] [,5]
#> red 0 0 0 0 0
#> green 0 0 0 0 0
#> blue 0 0 0 0 0
#> alpha 128 191 159 223 255