Skip to contents

Title Create a custom legend for a leaflet webmap

Usage

addCustomLegend(map, colors, labels, sizes, shapes, borders, opacity = 0.5)

Arguments

map

the leaflet map to add the legend to

colors

the colors, ideally as hex codes

labels

the character labels

sizes

the sizes, as a numeric vector

shapes

the character shapes

borders

the border colours, ideally as hex codes

opacity

the opacity, ranging from 0 (transparent) to 1 (opaque)

Examples

colors <- c("#E69F00", "#56B4E9", "#009E73")
labels <- c("One", "Two", "Three")
sizes <- c(10, 5, 7.5)
shapes <- c("square", "circle", "square")
borders <- c("#E69F00", "#56B4E9", "#009E73")
leaflet::leaflet() %>%
  addCustomLegend(colors, labels, sizes, shapes, borders)