ComeçarComece de graça

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.

Este exercício faz parte do curso

Interactive Maps with leaflet in R

Ver curso

Instruções do exercício

  • 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.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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
Editar e executar o código