Exercise

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.

Instructions

100 XP
  • Load the htmltools package.
  • Filter the ipeds data to create a data frame with only public colleges.
  • Create a leaflet map of public colleges.
  • Add the group argument to addCircleMarkers().