Introduction

These are the codes I used to create an interactive map of my study area/sites in Red Run Watershed. All credit goes to Nicole Williamson - a graduate MS student who shared with me her codes so that I could replicate them. Check out her work here.

Install and load the package “leaflet”

library (leaflet)

Load latitude and longitude data

library(readxl)
RR_benthic <- read_excel("F:/Thesis stuff/Data/Land cover data/Biological Sites/Benthos Site.xls")

Load RR watershed’s and subwatersheds’ boundary polygon files

library(rgdal) #load the package
rr_boundary <- readOGR("F:/Thesis stuff/Data/Land cover data/RR Benthic Sites Raster/RR Site 1/layers/globalwatershed.shp",GDAL1_integer64_policy = T)
b7_boundary <- readOGR("F:/Thesis stuff/Data/Land cover data/RR Benthic Sites Raster/RR Site 7/layers/globalwatershed.shp")
b9a_boundary <- readOGR("F:/Thesis stuff/Data/Land cover data/RR Benthic Sites Raster/RR Site 9A/layers/globalwatershed.shp")
b9_boundary <- readOGR("F:/Thesis stuff/Data/Land cover data/RR Benthic Sites Raster/RR Site 9/layers/globalwatershed.shp")

Create the map

leaflet(RR_benthic) %>% 
  addPolygons(data=rr_boundary,weight=5,col = '#b10026', smoothFactor = 0.5,
    opacity = 1.0, fillOpacity = 0.5) %>% 
  addPolygons(data=b7_boundary,weight=5,col = '#feb14c', smoothFactor = 0.5,
    opacity = 1.0, fillOpacity = 0.5) %>% 
  addPolygons(data=b9a_boundary,weight=5,col = '#fc4d2a', smoothFactor = 0.5,
    opacity = 1.0, fillOpacity = 0.5) %>% 
  addPolygons(data=b9_boundary,weight=5,col = '#ffeea1', smoothFactor = 0.5,
    opacity = 1.0, fillOpacity = 0.5) %>% 
  addProviderTiles(providers$Esri.NatGeoWorldMap) %>%
  addTiles() %>% addScaleBar() %>% addMarkers(lng=~Long,lat=~Lat,popup = ~ Site) 

Feedback and comments are welcome as my map does not look great at this moment. Check out this site to learn more about leaflet and perhaps you can make a better looking map.