if (FALSE) {
# Basic categorical legend
add_legend(map, "Population",
values = c("Low", "Medium", "High"),
colors = c("blue", "yellow", "red"),
type = "categorical")
# Continuous legend with custom styling using legend_style()
add_legend(map, "Income",
values = c(0, 50000, 100000),
colors = c("blue", "yellow", "red"),
type = "continuous",
style = legend_style(
background_color = "white",
background_opacity = 0.9,
border_width = 2,
border_color = "navy",
text_color = "darkblue",
font_family = "Times New Roman",
title_font_weight = "bold"
))
# Legend with custom styling using a list
add_legend(map, "Temperature",
values = c(0, 50, 100),
colors = c("blue", "yellow", "red"),
type = "continuous",
style = list(
background_color = "#f0f0f0",
title_size = 16,
text_size = 12,
shadow = TRUE,
shadow_color = "rgba(0,0,0,0.1)",
shadow_size = 8
))
# Dark legend with white element borders
add_legend(map, "Elevation",
values = c(0, 1000, 2000, 3000),
colors = c("#2c7bb6", "#abd9e9", "#fdae61", "#d7191c"),
type = "continuous",
style = legend_style(
background_color = "#2c3e50",
text_color = "white",
title_color = "white",
element_border_color = "white",
element_border_width = 1
))
# Categorical legend with circular patches and styling
add_categorical_legend(
map = map,
legend_title = "Population",
values = c("Low", "Medium", "High"),
colors = c("#FED976", "#FEB24C", "#FD8D3C"),
circular_patches = TRUE,
sizes = c(10, 15, 20),
style = legend_style(
background_opacity = 0.95,
border_width = 1,
border_color = "gray",
title_color = "navy",
element_border_color = "black",
element_border_width = 1
)
)
# Create reusable legend styling
dark_style <- legend_style(
background_color = "#2c3e50",
text_color = "white",
title_color = "white",
font_family = "Arial",
title_font_weight = "bold",
element_border_color = "white",
element_border_width = 1,
shadow = TRUE,
shadow_color = "rgba(0,0,0,0.3)",
shadow_size = 6
)
# Clear specific legends
clear_legend(map_proxy, legend_ids = c("legend-1", "legend-2"))
}
Run the code above in your browser using DataLab