This R Markdown document demonstrates how to create an interactive
map with clustering using the leaflet package and the
quakes dataset available in R. The quakes
dataset contains information about 1,000 earthquakes around Fiji since
1964.
library(leaflet)
data(quakes)
color_pal <- colorNumeric(palette = "viridis", domain = quakes$mag)
leaflet(data = quakes) %>%
addTiles() %>%
addCircleMarkers(
lat = ~lat,
lng = ~long,
radius = ~mag * 2,
color = ~color_pal(mag),
stroke = FALSE,
fillOpacity = 0.8,
popup = ~paste("Magnitude:", mag, "<br>Depth:", depth, "km"),
clusterOptions = markerClusterOptions()
) %>%
addLegend(
"bottomright",
pal = color_pal,
values = quakes$mag,
title = "Magnitude",
opacity = 1
)