This function plots x/y coordinates from a data.frame on a (leaflet) map. The coordinates are first converted to WGS84 in order to map them correctly on the leaflet map (@seealso transform_coordinates()). To do this, the original Coordinate Reference System (CRS) is asked.

plot_coordinates_on_map(df, col_x, col_y, projection, ...)

Arguments

df

A data.frame with a x and y coordinate columns.

col_x, col_y

Column names or positions of the x (longitude) and y (latitude) column. They are passed to vars_pull. These arguments are passed by expression and support quasiquotation (you can unquote column names or column positions).

projection

Projection string of class CRS-class (sp objects) or crs-class (sf objects) defining the current projection.

...

Additional arguments passed on to addCircleMarkers to customize points.

Value

Leaflet map with coordinates added as dots.

See also

Other GIS_utilities: guess_crs(), transform_coordinates()

Examples

if (FALSE) {
library(sf)
data_pts <- data.frame(
  id = c(1, 2, 3),
  lat = c(51.23031, 50.76931, 50.21439),
  lon = c(5.083980, 3.829593, 3.289044),
  stringsAsFactors = FALSE
)

# projection is of class CRS-class (sp)
if (requireNamespace("sp")) {
  proj_crs_sp <- CRS("+init=epsg:4269")
  plot_coordinates_on_map(data_pts, "lon", "lat", proj_crs_sp)
}

# projection is of class crs-class (sf)
proj_crs_sf <- st_crs(4269)
plot_coordinates_on_map(data_pts, "lon", "lat", proj_crs_sf)

# customize circles
plot_coordinates_on_map(data_pts, "lon", "lat", proj_crs_sf,
  radius = 5, color = "red", stroke = FALSE, fillOpacity = 0.75
)
}