Labels and Pop-ups

Interactive Maps with leaflet in R

Rich Majerus

Vice President of Strategy & Planning, Queens University of Charlotte

Piping and the ~ Operator

ipeds %>% 
 leaflet() %>% 
 addProviderTiles("CartoDB") %>% 
 addCircleMarkers(
               lng = ~lng, 
               lat = ~lat, 
               popup = ~name, 
               color = "#FF0000")

All college circle markers 1

# ipeds is specified 3 times
leaflet() %>% 
  addProviderTiles("CartoDB") %>% 
  addCircleMarkers(
              lng = ipeds$lng, 
              lat = ipeds$lat, 
              popup = ipeds$name, 
              color = "red")

All college circle markers 2

Interactive Maps with leaflet in R

All the Colors

ipeds %>% 
     leaflet() %>% 
     addProviderTiles("CartoDB")%>% 
     addCircleMarkers(
        lng = ~lng, lat = ~lat, 
        popup = ~name,color = "#FF0000")
Hex Decimal RGB Color
FF 255 Red
00 0 Green
00 0 Blue

Hex FF0000

= 16^1*15 + 16^0*15

= 16*15 + 1*15

= 240 + 15

= 255

Interactive Maps with leaflet in R

Building a Better Pop-up

addCircleMarkers(popup = ~name)

addCircleMarkers(popup = ~paste0(name, "-", sector_label)
addCircleMarkers(popup = ~paste0("<b>",name,"</b>"," <br/>",sector_label))

Custom popups

Interactive Maps with leaflet in R

Labels

ipeds %>% 
    leaflet()  %>% 
    addProviderTiles("CartoDB")  %>% 
    addCircleMarkers(label = ~name, radius = 2)

Custom labels

Interactive Maps with leaflet in R

Let's practice!

Interactive Maps with leaflet in R

Preparing Video For Download...