Mapping Public Colleges
We can add each sector to our map as a layer providing users with the ability to select which sectors are displayed. To do this we will make use of a new argument to the addCircleMarkers() function, called a group.
leaflet() %>%
addProviderTiles("CartoDB") %>%
addCircleMarkers(data = public,
label = ~htmlEscape(name),
group = "Public")
We'll integrate another feature into our map from the htmltools library. Wrapping our labels with the htmlEscape() function will sanitize characters that may be interpreted as HTML. This will prevent any of the college names from appearing with unintended formatting.
The color palette pal we created in Chapter 2 has been loaded for you.
Diese Übung ist Teil des Kurses
Interactive Maps with leaflet in R
Anleitung zur Übung
- Load the
htmltoolspackage. - Filter the
ipedsdata to create a data frame with only public colleges. - Create a
leafletmap of public colleges. - Add the
groupargument toaddCircleMarkers().
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Load the htmltools package
___
# Create data frame called public with only public colleges
public <- ___(ipeds, sector_label == "Public")
# Create a leaflet map of public colleges called m3
m3 <- leaflet() %>%
addProviderTiles("CartoDB") %>%
addCircleMarkers(data = ___, radius = 2, label = ~htmlEscape(name),
color = ~pal(sector_label), ___ = "Public")
m3