
Compute a color ramp scaled from white to a target color
get_color_scale.RdCompute a color ramp scaled from white to a target color
Value
A character vector of hexadecimal colors and/or "transparent", of length equal to n, or NULL if negative values exist.
Details
Interpolates RGB values between "white" and col.
Strictly positive values scale from frac_min (smallest positive value) to 1 (maximum value).
Values equal to 0 or NA return "transparent".
If negative values are present, a warning is issued and NULL is returned.
Examples
get_color_scale(c(0, 1, 5, 12, NA)) # with integer
#> [1] "transparent" "#FFA5A5" "#FF6969" "#FF0000" "transparent"
get_color_scale(c(0, 1.2, 5, 12, NA)) # with numeric
#> [1] "transparent" "#FFA5A5" "#FF6B6B" "#FF0000" "transparent"
get_color_scale(c(0, NA)) # all transparent
#> [1] "transparent" "transparent"
get_color_scale(c()) # empty character
#> character(0)
get_color_scale(c(2, 2, 2), col = "blue") # all maximum blue
#> [1] "#0000FF" "#0000FF" "#0000FF"
get_color_scale(c(-1, 2)) # NULL with warning
#> Warning: No negative value is allowed. NULL returned.
#> NULL