LoslegenKostenlos loslegen

A Cluster Approach

Rather than using layers to improve the usability of our map, we could elect to cluster the colleges by clustering groups of nearby colleges together to reduce the number of points on the map. Zooming in will cause the clusters to break apart and the individual colleges to appear. This can be a useful tactic for mapping a large number of points in a user-friendly manner.

We can cluster all of our colleges by setting the clusterOptions argument of addCircleMarkers() as follows.

ipeds %>% 
  leaflet() %>%
    addTiles() %>% 
    addCircleMarkers(clusterOptions = markerClusterOptions())

The ipeds data, htmltools library, and color palette pal have been loaded for you.

Diese Übung ist Teil des Kurses

Interactive Maps with leaflet in R

Kurs anzeigen

Anleitung zur Übung

  • Sanitize any html in our labels.
  • Color code colleges by sector using the pal color palette.
  • Cluster all colleges using clusterOptions.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

ipeds %>% 
    leaflet() %>% 
        addTiles() %>% 
        # Sanitize any html in our labels
        addCircleMarkers(radius = 2, label = ___(name),
                         # Color code colleges by sector using the `pal` color palette
                         color = ___(sector_label),
                         # Cluster all colleges using `clusterOptions`
                         ___ = ___()) 
Code bearbeiten und ausführen