Get startedGet started for free

Mapping All Colleges

Let's keep layering up and add for-profit colleges to our leaflet map that is stored in the m3 object.

After you print() the m3 map with public, private, and for-profit colleges as their own layers, then try removing all three layers and adding them back to the map in a different order.

The different college sectors are added back to the map as layers in the order you specify (i.e., the last sector that you select will be on top).

The color palette pal and the m3 map with public and private colleges have been loaded for you.

This exercise is part of the course

Interactive Maps with leaflet in R

View Course

Exercise instructions

  • Filter the ipeds data to create a data frame with only for-profit colleges and assign it to profit.
  • Create a leaflet map of public, private, and for-profit colleges.
  • Use the addLayersControl() function and overlayGroups argument to allow users to toggle all three sectors of colleges.
  • Center the map on the middle of the US and set the zoom level to 4.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create data frame called profit with only For-Profit colleges
___ <- filter(ipeds, sector_label == "For-Profit")  

# Add For-Profit colleges to `m3` as a new layer
m3 <- m3 %>% 
        addCircleMarkers(data = ___, radius = 2, label = ~htmlEscape(name),
                         color = ~pal(sector_label),   group = "___")  %>% 
        addLayersControl(overlayGroups = c("Public", "Private", "___"))  

# Center the map on the middle of the US with a zoom of 4
m4 <- m3 %>%
        ___(lat = 39.8282, lng = -98.5795, zoom = 4) 
        
m4
Edit and Run Code