Leaflet maps

Leaflet is an R package that allows for creating interactive maps. Features include panning and zooming, creating different layers like markers, circles, polygons, and attaching values to those geographic locations.

library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5     v purrr   0.3.4
## v tibble  3.1.6     v dplyr   1.0.8
## v tidyr   1.2.0     v stringr 1.4.0
## v readr   2.1.2     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(magrittr)
## 
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
## 
##     set_names
## The following object is masked from 'package:tidyr':
## 
##     extract
d1 <- utils::read.csv('SoilFinal.csv', na.strings="NA", header = T) %>% filter(StudyNumber==1)
library(leaflet)
d1.map <- leaflet(d1) %>% addTiles()
library(here)
## here() starts at C:/Users/ual-laptop/Desktop/ENVS 567_R
polygon <- here("C:/Users/ual-laptop/Desktop/ENVS 567_R/layers/POLYGON.shp") %>% sf::st_read()
## Reading layer `POLYGON' from data source 
##   `C:\Users\ual-laptop\Desktop\ENVS 567_R\layers\POLYGON.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 258 features and 6 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: -111.1132 ymin: 33.28637 xmax: -111.1007 ymax: 33.29823
## Geodetic CRS:  WGS 84
bins<-c(0,10,20,30,40,50,60,70,80,Inf)
cal<-colorBin(palette="YlOrRd", domain=d1$As..mg.kg., bins=bins)
leaflet(polygon) %>% addTiles() %>%
  addPolygons(fillColor = ~cal(d1$As..mg.kg), 
              fillOpacity = 1, 
              stroke=FALSE, 
              smoothFactor = 0.3, 
              label = ~paste0(title, ": ", 
                formatC(d1$As..mg.kg))) %>% 
  addLegend(pal = cal, 
              values = ~d1$As..mg.kg., 
             opacity = 1, 
             title="Metal Concentration [X] (mg/kg)")