R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.1
## ✔ purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(leaflet)
library(sf)
## Linking to GEOS 3.11.2, GDAL 3.7.2, PROJ 9.3.0; sf_use_s2() is TRUE
library(rgbif)
library(raster)
## Loading required package: sp
## 
## Attaching package: 'raster'
## 
## The following object is masked from 'package:dplyr':
## 
##     select
zono_observations <- occ_search(
  scientificName = "Zonotrichia albicollis",
  country = "US",
  hasCoordinate = TRUE,
  limit = 2000
)$data

zono_observations_CA <- occ_search(
  scientificName = "Zonotrichia albicollis",
  country = "CA",
  hasCoordinate = TRUE,
  limit = 2000
)$data

I had to pull the data down in two accessions due to an error in trying to combine both the “US” and “CA” country codes. It did not recognize “CA” as a valid code putting them both in a line, so I just ran the same code twice but pulling in the accessions for the different countries.

zono_obv_summer <- zono_observations_CA %>% filter(countryCode=="CA")

zono_obv_winter<- zono_observations %>% filter(countryCode %in% c("US"))
#Loading temp raster file, and downsampling because it's big
temperature_raster <- raster("temperature.tif")
downsampled_temp <- aggregate(temperature_raster, fact = 4)

map <- leaflet() %>% setView(lng = -79, lat = 37.8, zoom = 5) %>% addTiles() %>%
  addProviderTiles(providers$Esri.NatGeoWorldMap) %>% 
  addProviderTiles(providers$OpenTopoMap) %>%
 
  addCircleMarkers(data = zono_obv_summer, 
                   ~decimalLongitude, ~decimalLatitude, 
                   color = "#FFB6C1", fillOpacity = 1, radius = 3, 
                   popup = ~paste(scientificName, "<br>", eventDate),
                   group = "Zonotrichia albicollis summer observations") %>%
  addCircleMarkers(data = zono_obv_winter, 
                   ~decimalLongitude, ~decimalLatitude, 
                   color = "blue", fillOpacity = 1, radius = 3, 
                   popup = ~paste(scientificName, "<br>", eventDate),
                   group = "Zonotrichia albicollis winter observations") %>%
  addRasterImage(downsampled_temp, colors = "viridis", opacity = 0.7, group = "Temperature") %>%

  addLayersControl(
    overlayGroups = c("Zonotrichia albicollis summer observations", "Zonotrichia albicollis winter observations", "Temperature"),
    options = layersControlOptions(collapsed = FALSE)) %>%
 addLegend(position = "bottomright", 
            colors = c("#FFB6C1", "blue", "cyan"), 
            labels = c("Zonotrichia albicollis summer observations", "Zonotrichia albicollis winter observations", "Temperature"), 
            opacity = 1) %>%
  addLegend("bottomleft", title = "Elevation",
            pal = colorNumeric(palette = c("lightgreen", "green", "darkgreen", "yellow", "orange", "red"), domain = c(0, 2000)),
            values = c(0, 2000),
            labels = c("0-200m", "201-400m", "401-600m", "601-800m", "801-1000m", "1001-2000m"),opacity = 1)

map
# Latitude and Longitude for Montreal
montreal_coords <- c(45.508888, -73.561668)

# Latitude and Longitude for Philadelphia
philly_coords <- c(39.952583, -75.165222)

# Latitude and Longitude for Washington, DC
dc_coords <- c(38.889805, -77.009056)

map <- leaflet() %>% setView(lng = -79, lat = 37.8, zoom = 5) %>% addTiles() %>%
  addProviderTiles(providers$Esri.NatGeoWorldMap) %>% 
  addProviderTiles(providers$OpenTopoMap) %>%
 
  addCircleMarkers(data = zono_obv_summer, 
                   ~decimalLongitude, ~decimalLatitude, 
                   color = "#FFB6C1", fillOpacity = 1, radius = 3, 
                   popup = ~paste(scientificName, "<br>", eventDate),
                   group = "Zonotrichia albicollis summer observations") %>%
  addCircleMarkers(data = zono_obv_winter, 
                   ~decimalLongitude, ~decimalLatitude, 
                   color = "blue", fillOpacity = 1, radius = 3, 
                   popup = ~paste(scientificName, "<br>", eventDate),
                   group = "Zonotrichia albicollis winter observations") %>%
  addRasterImage(downsampled_temp, colors = "viridis", opacity = 0.7, group = "Temperature") %>%

  addLayersControl(
    overlayGroups = c("Zonotrichia albicollis summer observations", "Zonotrichia albicollis winter observations", "Temperature"),
    options = layersControlOptions(collapsed = FALSE)) %>%
 addLegend(position = "bottomright", 
            colors = c("#FFB6C1", "blue", "cyan"), 
            labels = c("Zonotrichia albicollis summer observations", "Zonotrichia albicollis winter observations", "Temperature"), 
            opacity = 1) %>%
  addLegend("bottomleft", title = "Elevation",
            pal = colorNumeric(palette = c("lightgreen", "green", "darkgreen", "yellow", "orange", "red"), domain = c(0, 2000)),
            values = c(0, 2000),
            labels = c("0-200m", "201-400m", "401-600m", "601-800m", "801-1000m", "1001-2000m"),opacity = 1) %>%
  addMarkers(lng = montreal_coords[2], lat = montreal_coords[1], label = "Montreal", labelOptions = labelOptions(noHide = TRUE)) %>%
  addMarkers(lng = philly_coords[2], lat = philly_coords[1], label = "Philadelphia", labelOptions = labelOptions(noHide = TRUE)) %>%
  addMarkers(lng = dc_coords[2], lat = dc_coords[1], label = "Washington, D.C.", labelOptions = labelOptions(noHide = TRUE))
map
syrupIcon <- makeIcon(
  iconUrl = "syrup.jpg",
  iconWidth = 45, 
  iconHeight = 45, 
  iconAnchorX = 25,  
  iconAnchorY = 25)

capitolIcon <- makeIcon(
  iconUrl = "hartford.webp",
  iconWidth = 45, 
  iconHeight = 45, 
  iconAnchorX = 25,  
  iconAnchorY = 25)
# Latitude and Longitude for Montreal
montreal_coords <- c(45.508888, -73.561668)

# Latitude and Longitude for Philadelphia
philly_coords <- c(39.952583, -75.165222)

# Latitude and Longitude for Washington, DC
dc_coords <- c(38.889805, -77.009056)

map <- leaflet() %>% setView(lng = -79, lat = 37.8, zoom = 5) %>% addTiles() %>%
  addProviderTiles(providers$Esri.NatGeoWorldMap) %>% 
  addProviderTiles(providers$OpenTopoMap) %>%
 
  addCircleMarkers(data = zono_obv_summer, 
                   ~decimalLongitude, ~decimalLatitude, 
                   color = "#FFB6C1", fillOpacity = 1, radius = 3, 
                   popup = ~paste(scientificName, "<br>", eventDate),
                   group = "Zonotrichia albicollis summer observations") %>%
  addCircleMarkers(data = zono_obv_winter, 
                   ~decimalLongitude, ~decimalLatitude, 
                   color = "blue", fillOpacity = 1, radius = 3, 
                   popup = ~paste(scientificName, "<br>", eventDate),
                   group = "Zonotrichia albicollis winter observations") %>%
  addRasterImage(downsampled_temp, colors = "viridis", opacity = 0.7, group = "Temperature") %>%

  addLayersControl(
    overlayGroups = c("Zonotrichia albicollis summer observations", "Zonotrichia albicollis winter observations", "Temperature"),
    options = layersControlOptions(collapsed = FALSE)) %>%
 addLegend(position = "bottomright", 
            colors = c("#FFB6C1", "blue", "cyan"), 
            labels = c("Zonotrichia albicollis summer observations", "Zonotrichia albicollis winter observations", "Temperature"), 
            opacity = 1) %>%
  addLegend("bottomleft", title = "Elevation",
            pal = colorNumeric(palette = c("lightgreen", "green", "darkgreen", "yellow", "orange", "red"), domain = c(0, 2000)),
            values = c(0, 2000),
            labels = c("0-200m", "201-400m", "401-600m", "601-800m", "801-1000m", "1001-2000m"),opacity = 1) %>%
  addMarkers(lng = montreal_coords[2], lat = montreal_coords[1], label = "Montreal", labelOptions = labelOptions(noHide = TRUE)) %>%
  addMarkers(lng = philly_coords[2], lat = philly_coords[1], label = "Philadelphia", labelOptions = labelOptions(noHide = TRUE)) %>%
  addMarkers(lng = dc_coords[2], lat = dc_coords[1], label = "Washington, D.C.", labelOptions = labelOptions(noHide = TRUE)) %>%
  addMarkers(lng = -75.695000, lat = 45.424721, label = "Syrup Capitol", labelOptions = labelOptions(noHide = TRUE), icon = syrupIcon) %>%
  addMarkers(lng = -72.685097, lat = 41.763710, label = "Hartford, CT", labelOptions = labelOptions(noHide = TRUE), icon = capitolIcon)
map

I designed my map with a temperature layer for the contiguous United States with a color gradient to indicate the temperature gradient. It shows that there are cooler temperatures towards the north, and warmer to the south. On the legend the “Temperature” layer is colored by cyan to show that a majority of the US accessions were in a cooler climate. I also colored the observations in the warmer and cooler months differently to show the migration pattern as weather changes. The blue circles indicate that the birds were in the United States in cooler months, whereas the pink colors show that they flew to Canada for the summer months. I labeled five cities total, but the three most popolous closest to my accession points were Montreal, Philadelphia, and Washington, DC. The other two cities are indicated by images, with a bottle of syrup for Ottawa, the capitol of Canada, and the capitol building for Hartford, CT, since we are based in Connecticut.