Convert percentiles to hexadecimal colors
Usage
pctile2colorhex(
x,
colorbins = c(0, ejscreen_color_defaults()$colorbins, 100),
colorfills = ejscreen_color_defaults()$colorfills,
na.color = NA
)Arguments
- x
Numeric vector of percentiles on a 0-100 scale.
- colorbins
Strictly increasing bin boundaries INCLUDING endpoints (normally 0 and 100), unlike
pctile2color()'s interior cutoffs.- colorfills
Color palette passed to
leaflet::colorBin(). Defaults to gray, yellow, orange, and red; other palette lengths are interpolated.- na.color
Color for missing or out-of-range values, default
NA.
Value
Character vector of hexadecimal colors, as long as x.
Out-of-range values also produce a warning from Leaflet.
Details
Cutoffs belong to the higher bin; the final endpoint is included. The default scheme has four bins. With explicit boundaries, values are checked against their range rather than an additional 0-100 restriction.
Examples
EJAM:::pctile2colorhex(c(79, 80, 90, 95, 100, NA))
# #BEBEBE, #FFFF00, #FFA500, #FF0000, #FF0000, NA
defaults <- EJAM:::ejscreen_color_defaults()
EJAM:::pctile2colorhex(c(79, 80, 95, NA),
colorbins = c(0, defaults$colorbins, 100),
colorfills = defaults$colorfills, na.color = "#808080")