This creates a basic map centered at a specific location.
leaflet() %>%
addTiles() %>%
setView(lng = 23.7922, lat = 61.4882, zoom = 13)
You can add markers with popups by using
addMarkers().
leaflet() %>%
addTiles() %>%
addMarkers(lng = 23.7526, lat = 61.4971, popup = "Hello Tampere!")
locations <- data.frame(
name = c("Helsinki", "Stockholm", "Copenhagen"),
lat = c(60.1699, 59.3293, 55.6761),
lng = c(24.9384, 18.0686, 12.5683)
)
leaflet(locations) %>%
addTiles() %>%
addMarkers(~lng, ~lat, popup = ~name)
You can draw circles, rectangles, and polygons.
leaflet() %>%
addTiles() %>%
addCircles(lng = 23.830898, lat = 61.451938, radius = 100, color = "blue", popup = "Home Sweet Home")
leaflet() initializes the map.addTiles() adds the background tiles.addMarkers() adds points of interest.addCircles() and other shape functions add visual
elements.