Chapter 2 Overview

Interactive Maps with leaflet in R

Rich Majerus

Vice President of Strategy & Planning, Queens University of Charlotte

Where We Left Off

leaflet() %>% 
    addProviderTiles("CartoDB") %>% 
    addMarkers(lng = dc_hq$lon, lat = dc_hq$lat, popup = dc_hq$hq)

Chapter one final map

Interactive Maps with leaflet in R

Cleaning up the Base Map

m <- m %>% 
    setView(lat = 50.881363, 
            lng = 4.717863,
            zoom = 5)

ClearBounds() example 1

# Restore view based on 
# data displayed on map
m  %>%
    clearBounds()

ClearBounds() example 2

Interactive Maps with leaflet in R

Cleaning up the Base Map

# Restore view based on 
# data displayed on map
m  %>%
    clearBounds()

clearMarkers() example 1

# Remove markers
m  %>%
    clearBounds() %>% 
    clearMarkers()

clearMarkers() example 2

Interactive Maps with leaflet in R

IPEDS

  • Integrated Postsecondary Education Data System (IPEDS)

  • Administered by National Center for Education Statistics (NCES)

  • Data from all institutions participating in federal student financial aid programs

    • colleges
    • universities
    • technical and vocational institutions
Interactive Maps with leaflet in R

Our IPEDS Dataset

> glimpse(ipeds)
Observations: 3,146
Variables: 5
$ name         <chr> "A T Still University of Health Sciences",...
$ lng          <dbl> -92.58918, -99.70954, -83.52828, -93.29968, ...
$ lat          <dbl> 40.19365, 32.46915, 31.48189, 44.85621, 29.65008, ...
$ state        <chr> "MO", "TX", "GA", "MN", "FL", "CA", "CA", "CA",... 
$ sector_label <chr> "Private", "Private", "Public", "For-Profit", ...
Interactive Maps with leaflet in R

Our IPEDS Dataset

ipeds %>% group_by(state) %>% count %>% arrange(desc(n))
# A tibble: 56 x 2
# Groups:   state [56]
   state     n
   <chr> <int>
 1    CA   286
 2    NY   239
 3    PA   164
 4    FL   160
 5    TX   157
Interactive Maps with leaflet in R

Where We are Going in Chapter 2

  • Filter the data to California colleges
  • Map all of the colleges in California
  • Use circle markers instead of pins
  • Color our markers by sector

California colleges by sector

Interactive Maps with leaflet in R

Let's practice!

Interactive Maps with leaflet in R

Preparing Video For Download...