Adds a legend for salinity values to the bottom right of a leaflet map.
Usage
add_salinity_legend(
map,
palette = "YlGnBu",
domain = c(0, 40),
color_function = NULL,
position = "bottomright",
opacity = 0.8
)Arguments
- map
A leaflet map object
- palette
Character string specifying the color palette name (default: "YlGnBu")
- domain
Numeric vector of length 2 specifying the domain range for colors (default: c(0, 40))
- color_function
Optional pre-created color function (overrides palette and domain if provided)
- position
Character string specifying the position of the legend (default: "bottomright")
- opacity
Numeric opacity of the legend (default: 0.8)
Examples
# generate salinity data to map
to_map <- dplyr::left_join(mssnd_salinity$daily, mssnd_salinity$siteInfo) |>
dplyr::filter(date == as.Date("2023-06-01"))
#> Joining with `by = join_by(site_no)`
# create base map
my_map <- create_mssnd_basemap()
# Add points, using default color palette
my_map |>
add_salinity_points(to_map)
# Add points and legend, using default color palette
my_map |>
add_salinity_points(to_map) |>
add_salinity_legend()
# Add points and legend, using non-default existing palette
my_map |>
add_salinity_points(to_map, palette = "Spectral") |>
add_salinity_legend(palette = "Spectral")
# Add points and legend, using custom domain
my_map |>
add_salinity_points(to_map, domain = c(5, 35)) |>
add_salinity_legend(domain = c(5, 35))
#> Warning: Some values were outside the color scale and will be treated as NA
#> Warning: Some values were outside the color scale and will be treated as NA