
Create an interpolation expression with automatic palette and break calculation
Source:R/style_helpers.R
interpolate_palette.Rd
This function creates an interpolation expression by automatically calculating break points using different methods and applying a color palette. It handles the values/stops matching automatically and supports the same classification methods as the step functions.
Usage
interpolate_palette(
column,
data_values,
method = "equal",
n = 5,
palette = viridisLite::viridis,
na_color = "grey"
)
Arguments
- column
The name of the column to use for the interpolation.
- data_values
A numeric vector of the actual data values used to calculate breaks.
- method
The method for calculating breaks. Options are "equal" (equal intervals), "quantile" (quantile breaks), or "jenks" (Jenks natural breaks). Defaults to "equal".
- n
The number of break points to create. Defaults to 5.
- palette
A function that takes n and returns a character vector of colors. Defaults to viridisLite::viridis.
- na_color
The color to use for missing values. Defaults to "grey".
Value
A list of class "mapgl_continuous_scale" containing the interpolation expression and metadata.
Examples
if (FALSE) { # \dontrun{
# Create continuous color scale
data_values <- c(10, 25, 30, 45, 60, 75, 90)
scale <- interpolate_palette("value", data_values, method = "equal", n = 5)
# Use in a layer
add_fill_layer(map, fill_color = scale$expression)
# Extract legend information
labels <- get_legend_labels(scale, format = "currency")
colors <- scale$colors
} # }