Creates a numeric color scale spec that is resolved during widget compilation.
Use in color/fill_color aesthetics (e.g. fill_color = color_numeric(~x)).
Usage
color_numeric(
expr,
palette = NULL,
domain = NULL,
steps = 256L,
na_color = "#00000000",
reverse = FALSE,
clamp = TRUE
)Arguments
- expr
A formula selecting a numeric column (e.g.
~value).- palette
NULL, a palette name (passed togrDevices::hcl.colors()), or a vector of colors.- domain
Optional numeric range
c(min, max); defaults to data range.- steps
Number of palette steps for interpolation.
- na_color
Color used for missing values.
- reverse
Logical; reverse the palette.
- clamp
Logical; if
TRUE, clamp values outsidedomainto the ends.
Examples
if (requireNamespace("sf", quietly = TRUE)) {
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
maplamina(nc) |>
add_polygons(fill_color = color_numeric(~BIR74))
}