Learn R Programming

tikatuwq (version 0.8.2)

plot_map: Plot interactive map of sampling points (default Leaflet pins)

Description

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
)

Value

a leaflet htmlwidget.

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.

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

Run this code
if (FALSE) { # requireNamespace("leaflet", quietly = TRUE)
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)")
}

Run the code above in your browser using DataLab