
Visualize Points on a Map with Optional Layers and Metadata
visualize_points.RdThis function takes a data frame containing latitude and longitude coordinates
(default columns: 'decimalLatitude' and 'decimalLongitude') and optionally additional
columns (e.g., species, locality, year, dataset name). It visualizes the points
on a map using the leaflet package, and the popup will show the coordinates along
with any other provided information if the user chooses to display it. Additionally,
it allows loading a vector or raster layer to the map, and the points will be displayed
on top of this layer.
Usage
visualize_points(
points_df,
latitude_col = "decimalLatitude",
longitude_col = "decimalLongitude",
show_extra_columns = FALSE,
layer = NULL
)Arguments
- points_df
A data frame containing columns named 'decimalLatitude' and 'decimalLongitude'. Optionally, the data frame can include other columns such as species, locality, year, dataset name, or any additional metadata.
- latitude_col
The name of the latitude column in
points_df. Default is 'decimalLatitude'.- longitude_col
The name of the longitude column in
points_df. Default is 'decimalLongitude'.- show_extra_columns
A logical value indicating whether to display extra columns (e.g., species, locality, year) in the popup. Default is FALSE.
- layer
An optional vector or raster layer (e.g., an sf object or a raster object) to be added to the map. The points will be plotted on top of this layer.
Value
A leaflet map object with the points plotted on it, and optionally, an additional
vector or raster layer. The popup will display the coordinates and, if show_extra_columns is TRUE,
any additional columns provided.
Examples
# Example: Visualize locations along the Danube River with fish species data
fish_data_2 <- fish_data %>%
select(species, decimalLatitude, decimalLongitude)
#> Error in fish_data %>% select(species, decimalLatitude, decimalLongitude): could not find function "%>%"
visualize_points(fish_data_2, show_extra_columns = TRUE)
#> Error: object 'fish_data_2' not found
# Example with additional vector layer
visualize_points(fish_data_2, layer = danube_basin, show_extra_columns = TRUE)
#> Error: object 'fish_data_2' not found