This web page features an interactive map created
with Leaflet in R.
Explore different locations and enjoy a modern, sleek map style.
library(leaflet)
# Define locations with names
locations <- data.frame(
name = c("New York City", "Los Angeles", "Chicago", "Houston", "Miami"),
lat = c(40.7128, 34.0522, 41.8781, 29.7604, 25.7617),
lng = c(-74.0060, -118.2437, -87.6298, -95.3698, -80.1918)
)
# Create an interactive Leaflet map
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>% # Sleek modern tiles
setView(lng = -98.5795, lat = 39.8283, zoom = 4) %>% # Centered on the USA
addMarkers(
data = locations,
~lng, ~lat,
popup = ~paste0("<b style='color:#d9534f;'>", name, "</b><br>Coordinates: ", round(lat, 3), ", ", round(lng, 3))
)