1. Creating a Basic Leaflet Map

This creates a basic map centered at a specific location.

leaflet() %>% 
  addTiles() %>% 
  setView(lng = 23.7922, lat = 61.4882, zoom = 13)

2. Adding Markers and Popups

You can add markers with popups by using addMarkers().

leaflet() %>% 
  addTiles() %>% 
  addMarkers(lng = 23.7526, lat = 61.4971, popup = "Hello Tampere!")

3. Adding Multiple Markers with Popups

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)

4. Drawing Shapes on the Map

You can draw circles, rectangles, and polygons.

leaflet() %>% 
  addTiles() %>% 
  addCircles(lng = 23.830898, lat = 61.451938, radius = 100, color = "blue", popup = "Home Sweet Home")

Summary