add_legend: Add Legend

View source: R/map_legend.R

add_legendR Documentation

Add Legend

Description

Add a custom legend to the map

Usage

add_legend(map, legend, layer_id)

Arguments

map

a mapdeck map object

legend

either a logical indiciating if the legend(s) should be displayed, or a named list indicating which colour attributes should be included in the legend.

layer_id

single value specifying an id for the layer. Use this value to distinguish between shape layers of the same type. Layers with the same id are likely to conflict and not plot correctly

Examples



sf <- spatialwidget::widget_melbourne
sf$my_colour <- ifelse( substr(sf$SA2_NAME, 1, 1) == "A", "#00FF00FF", "#FF0000FF")

l1 <- legend_element(
	variables = c("Begins with A", "Doesn't begin with A")
	, colours = c("#00FF00FF", "#FF0000FF")
	, colour_type = "fill"
	, variable_type = "category"
)
js <- mapdeck_legend(l1)

set_token(secret::get_secret("MAPBOX"))
mapdeck() %>%
  add_legend(legend = js, layer_id = "my_layer")


mapdeck() %>%
  add_legend(legend = js, layer_id = "my_layer") %>%
  clear_legend(layer_id = "my_layer")




SymbolixAU/mapdeck documentation built on April 14, 2025, 2:07 a.m.