Add a categorical legend to a Mapbox GL map
add_categorical_legend.Rd
This function adds a categorical legend to a Mapbox GL map. It supports customizable colors, sizes, and shapes for legend items.
Usage
add_categorical_legend(
map,
legend_title,
values,
colors,
circular_patches = FALSE,
position = "top-left",
unique_id = NULL,
sizes = NULL
)
Arguments
- map
A map object created by the
mapboxgl
function.- legend_title
The title of the legend.
- values
A vector of categories or values to be displayed in the legend.
- colors
The corresponding colors for the values. Can be a vector of colors or a single color.
- circular_patches
Logical, whether to use circular patches in the legend. Default is FALSE.
- position
The position of the legend on the map. One of "top-left", "bottom-left", "top-right", "bottom-right". Default is "top-left".
- unique_id
A unique ID for the legend container. If NULL, a random ID will be generated.
- sizes
An optional numeric vector of sizes for the legend patches, or a single numeric value. If provided as a vector, it should have the same length as
values
. Ifcircular_patches
isFALSE
(for square patches), sizes represent the width and height of the patch in pixels. Ifcircular_patches
isTRUE
, sizes represent the radius of the circle.