Necessary packages

  • leaflet
  • dplyr

Why are these not beamer slides?

  • Because leaflet is a package that generates HTML output

Reminder about the %>% operator

  • This is called the “pipe” operator.
  • It tells R to forward the value of the past expression as an input into the next expression
  • (It’s better explained with an example)
log(c(1,2,3,4))
## [1] 0.0000000 0.6931472 1.0986123 1.3862944
# Is the same as: 
c(1,2,3,4) %>% 
  log()
## [1] 0.0000000 0.6931472 1.0986123 1.3862944

Using pipes is also called “chaining”

  • The point is to make complicated nested operations easier to read through
data(airquality)
airquality %>%
  select(Wind) %>%
  filter(Wind > 20) %>%
  log()
##       Wind
## 1 3.000720
## 2 3.030134

The leaflet package uses %>% to build maps

leaflet() %>%
      addTiles()

leaflet maps are

  • Based on OpenStreetMap
  • Rendered in HTML (webpages)
  • Interactive
  • Highly customizable

Here’s where we are

map <- leaflet() %>%
          addTiles() %>%
          addMarkers(lat=33.947474, lng=-83.373671, popup="Conner Hall Room 307")
map # This map is interactive

Let’s add some random locations around Athens

# Conner hall is at lat = 33.95 and long = -83.37
athensPlaces <- data.frame(lat = runif(20, min = 33.93, max = 33.97), 
                           lng = runif(20, min = -83.39, max = -83.35))
map2 <- map  %>% addMarkers(lat=athensPlaces$lat, lng=athensPlaces$lng)
map2

You can make markers that dynamically bunch

# Conner hall is at lat = 33.95 and long = -83.37
map2 <- map  %>% addMarkers(lat=athensPlaces$lat, lng=athensPlaces$lng
                            , clusterOptions  = markerClusterOptions())
map2

You can do so much more!

  • That’s for another time