Skip to contents

Creates an interactive Leaflet map of sampling points using the default Leaflet marker (blue pin). Latitude/longitude are autodetected from columns lat and lon. If these columns are not present, but latitude and/or longitude exist, they are automatically copied to lat and lon. You may group layers with group_by (e.g., "year") and show popups with popup.

If color_by is provided, a legend is drawn to describe the values, but markers are not colorized (the default Leaflet pin has fixed style).

Usage

plot_map(
  df,
  color_by = NULL,
  popup = NULL,
  group_by = NULL,
  legend_title = NULL,
  na_rm = TRUE
)

Arguments

df

data.frame/tibble with coordinates; must contain lat/lon (or latitude/longitude, which will be mapped automatically).

color_by

optional column used to build a legend (numeric or factor). It does not change the marker color.

popup

optional column name with popup/tooltip text.

group_by

optional column name to create overlay layers (e.g., "year").

legend_title

optional legend title (used when color_by is set).

na_rm

logical; if TRUE (default) remove rows with invalid coordinates.

Value

a leaflet htmlwidget.

Details

The function expects coordinates in columns named lat and lon. If those columns are not found, but latitude and/or longitude are present, they are copied to lat and lon respectively before plotting.

Examples

data("wq_demo", package = "tikatuwq")
d2 <- wq_demo |>
  validate_wq() |>
  iqa(na_rm = TRUE)
d2$year <- as.integer(format(d2$data, "%Y"))

# Marcadores padrao + legenda de IQA
plot_map(d2, color_by = "IQA", group_by = "year", popup = "ponto",
         legend_title = "IQA (0–100)")
#> Warning: 5 registros removidos por coordenadas invalidas.