rtmap

Marker cluster in tmap


I am currently using tmap to create interactive maps. Since the results are quite cluttered at initial zoom (see image below), I would like to implement marker clusters.

enter image description here

I know leaflet allows using marker clusters by adding the parameter clusterOptions = markerClusterOptions() to addMarkers() or addCircleMarkers() calls (Source: https://rstudio.github.io/leaflet/markers.html) but haven't found how to achieve that using tmap.

How can I add marker clusters in tmap?


Solution

  • If anyone from the future is curious, tmap supports clustering by setting clustering = TRUE in tm_symbols.

    library(tmap)
    
    data(metro)
    tmap_mode("view")
    tm_shape(metro) + tm_dots(clustering = T)
    

    enter image description here