View source: R/plot_coordinates_on_map.R
plot_coordinates_on_map | R Documentation |
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, ...)
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 |
projection |
Projection string of class CRS-class ( |
... |
Additional arguments passed on to
|
Leaflet map with coordinates added as dots.
Other GIS_utilities:
guess_crs()
,
transform_coordinates()
## Not run:
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
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.