Objective

The purpose of this project is to create an interactive map with Leaflet using R markdown. The following is an example of the location of Simon Fraser University on the map.

Map in Action

library(leaflet)
library(dplyr)
SFU_link <- c("<a href='https://www.sfu.ca/'>Simon Fraser University</a>")
SFU <- leaflet() %>% 
    addTiles() %>% 
    addMarkers(lat=49.278094, lng=-122.919883, popup=SFU_link)
SFU

Here, we have seen the location of Simon Fraser University on the map, and it locates in Burnaby, BC, Canada.

 

Some Random Coordinates Within SFU

Below is an example of generating some random coordinates. By zooming in the map, we can see each cluster separates into individual locations.

set.seed(123)
df <- data.frame(lat=runif(50, min=49.276, max=49.278),
                 lng=runif(50, min=-122.926, max=-122.907)) 

df %>% 
    leaflet() %>% 
    addTiles() %>% 
    addMarkers(clusterOptions = markerClusterOptions())