Mapping a State's Colleges

Interactive Maps with leaflet in R

Rich Majerus

Vice President of Strategy & Planning, Queens University of Charlotte

How many 4-year colleges are there in Maine?

ipeds %>% 
   filter(state == "ME")
# A tibble: 21 x 5
                     name       lng      lat state sector_label
                    <chr>     <dbl>    <dbl> <chr>        <chr>
1           Bates College -70.20333 44.10530    ME      Private
2         Bowdoin College -69.96524 43.90690    ME      Private
3           Colby College -69.66337 44.56421    ME      Private
4 College of the Atlantic -68.22885 44.39958    ME      Private
...
Interactive Maps with leaflet in R

Mapping a State's Colleges

# Assuming 'lng' and 'lat' are longitude and latitude, respectively
maine_colleges_map <- 
  leaflet() %>% 
  addProviderTiles("CartoDB") %>% 
  addMarkers(data = maine_colleges)

Maine college markers 1

Interactive Maps with leaflet in R

Mapping a State's Colleges

maine_colleges_map <- 
   leaflet() %>% 
   addProviderTiles("CartoDB")%>% 
   addMarkers(data = maine)

Maine college markers 1

# adding more markers will 
# not remove existing markers
maine_colleges_map %>%
   addCircleMarkers(data = maine)

Maine college markers 2

Interactive Maps with leaflet in R

Mapping a State's Colleges

# adding more markers will 
# not remove existing markers
maine_colleges_map %>% 
   addCircleMarkers(data = maine)

Maine college markers 2

maine_colleges_map %>% 
   clearMarkers() %>% 
   addCircleMarkers(data = maine, 
                    radius = 3)

Maine college markers 3

Interactive Maps with leaflet in R

Mapping a State's Colleges

maine_colleges_map <- 
  maine_colleges_map %>% 
  clearMarkers %>% 
  addCircleMarkers(
          data = maine_colleges, 
          radius = 3)

Maine college markers 3

maine_colleges_map %>% 
  addCircleMarkers(
           data = maine_colleges, 
           radius = 4,
           color = "red",
           popup = ~name)

Maine college markers 4

Interactive Maps with leaflet in R

Let's practice!

Interactive Maps with leaflet in R

Preparing Video For Download...