Color Coding Colleges

Interactive Maps with leaflet in R

Rich Majerus

Vice President of Strategy & Planning, Queens University of Charlotte

Adding Color (and Information)

Oregon colleges 1

Oregon colleges 2

Interactive Maps with leaflet in R

Remembering your Colors

Oregon colleges 3

Interactive Maps with leaflet in R

colorFactor()

OR <- ipeds %>% 
      filter(state == "OR")

pal <- colorFactor(palette = c("red", "blue", "#9b4a11"), levels = c("Public", "Private", "For-Profit"))
oregon_colleges <- OR %>% 
        leaflet() %>% 
        addProviderTiles("CartoDB") %>% 
        addCircleMarkers(radius = 2, 
                         color = ~pal(sector_label), label = ~name)
oregon_colleges %>% 
    addLegend(position = "bottomright",pal = pal, 
              values = c("Public", "Private", "For-Profit"))
Interactive Maps with leaflet in R

colorNumeric()

admit <- admit %>% 
         filter(!is.na(rate),rate < 50, rate > 0)
 pal <- colorNumeric(palette = "Reds", domain = c(1:50), 
                     reverse = TRUE)
admit_map <- admit %>% 
    leaflet() %>% 
    addProviderTiles("CartoDB")  %>% 
    addCircleMarkers(radius = 4, color = ~pal(rate), 
                     label = ~name)  %>%
    addLegend(title = "Admit Rate", pal = pal, values = c(1:50), 
              position = "bottomright")
Interactive Maps with leaflet in R

College admit rates

Interactive Maps with leaflet in R

Picking a Color Palette

# see https://colorbrewer2.org/ for interactive examples
library(RColorBrewer)
display.brewer.all()

RColorBrewer palettes

Interactive Maps with leaflet in R

Let's practice!

Interactive Maps with leaflet in R

Preparing Video For Download...