add_legend | R Documentation |
Add a custom legend to the map
add_legend(map, legend, layer_id)
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 |
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.