r format(Sys.Date(), “%B %d, %Y”) (This date updates automatically when you knit the document.)
Interactive Leaflet Map
library(leaflet)
# Example location (Lawrence, KS). Change these to your favorite place.
lat <- 38.9717
lng <- -95.2353
leaflet() |>
addProviderTiles(providers$CartoDB.Positron, group = "Light") |>
addProviderTiles(providers$Esri.WorldImagery, group = "Satellite") |>
setView(lng = lng, lat = lat, zoom = 13) |>
# A marker with a popup
addMarkers(lng = lng, lat = lat,
popup = paste0(
"<b>Hello!</b><br>",
"This map was made with <code>leaflet</code> in R.<br>",
"Created on: ", format(Sys.Date(), "%B %d, %Y")
)) |>
# A styled circle to show an area of interest
addCircles(lng = lng, lat = lat,
radius = 1200,
weight = 2,
opacity = 0.9,
fillOpacity = 0.2,
popup = "Area of interest (1.2 km radius)") |>
# Layer controls + extras
addLayersControl(
baseGroups = c("Light", "Satellite"),
options = layersControlOptions(collapsed = FALSE)
) |>
addScaleBar(position = "bottomleft") |>
addMiniMap(toggleDisplay = TRUE)
Notes
-You can change the location by editing lat and lng.
-Add more markers (favorite restaurants, crash hotspots, etc.) to show creativity.