setwd("C:/EEB 4100/Data/Lab 5")
getwd()
## [1] "C:/EEB 4100/Data/Lab 5"
library(leaflet)
library(rgbif)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(elevatr)
## elevatr v0.99.0 NOTE: Version 0.99.0 of 'elevatr' uses 'sf' and 'terra'. Use
## of the 'sp', 'raster', and underlying 'rgdal' packages by 'elevatr' is being
## deprecated; however, get_elev_raster continues to return a RasterLayer. This
## will be dropped in future versions, so please plan accordingly.
library(sf)
## Linking to GEOS 3.11.2, GDAL 3.7.2, PROJ 9.3.0; sf_use_s2() is TRUE
library(raster)
## Loading required package: sp
##
## Attaching package: 'raster'
## The following object is masked from 'package:dplyr':
##
## select
wcrane_gbif <- occ_download_get(key = "0001012-240229165702484", overwrite = TRUE) %>%
occ_download_import(stern_gbif_download, na.strings = c("", NA))
## Download file size: 0.4 MB
## On disk at C:\EEB 4100\Data\Lab 5\0001012-240229165702484.zip
wcrane_obv_summer <- wcrane_gbif %>% filter(countryCode=="CA")
wcrane_obv_winter <- wcrane_gbif %>% filter (countryCode=="US")
temperature_raster <- raster("temperature/temperature.tif")
downsampled_temp <- aggregate(temperature_raster, fact = 4)
chicago_coords <- c(41.8781, -87.6298)
corpus_christi_coords <- c(27.8006, -97.3964)
orlando_coords <- c(28.5384, -81.3789)
WhoopingCraneIcon <- makeIcon(
iconUrl = "Whooping_Crane.png",
iconWidth = 30,
iconHeight = 30,
iconAnchorX = 25,
iconAnchorY = 25)
map <- leaflet() %>% setView(lng = -79, lat = 37.8, zoom = 5) %>% addTiles() %>%
addProviderTiles(providers$Esri.NatGeoWorldMap) %>%
addProviderTiles(providers$OpenTopoMap) %>%
addCircleMarkers(data = wcrane_obv_summer,
~decimalLongitude, ~decimalLatitude,
color = "#D41159", fillOpacity = 1, radius = 3, popup = ~paste(scientificName, "<br>", eventDate),group = "Grus americana Summer Observations") %>%
addCircleMarkers(data = wcrane_obv_winter,
~decimalLongitude, ~decimalLatitude,
color = "#1A85FF", fillOpacity = 1, radius = 3, popup = ~paste(scientificName, "<br>", eventDate),group = "Grus americana Winter Observations") %>%
addRasterImage(downsampled_temp, colors = "#40B0A6", opacity = 0.5, group = "Temperature") %>%
addLayersControl(
overlayGroups = c("Grus americana Summer Observations", "Grus americana Winter Observations", "Temperature"),
options = layersControlOptions(collapsed = FALSE)) %>%
addLegend(position = "bottomright", title = "Legend",
colors = c("#D41159", "#1A85FF", "#40B0A6"),
labels = c("Grus americana Summer Observations", "Grus americana 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 = chicago_coords[2], lat = chicago_coords[1], label = "Chicago", labelOptions = labelOptions(noHide = TRUE)) %>%
addMarkers(lng = corpus_christi_coords[2], lat = corpus_christi_coords[1], label = "Corpus Christi", labelOptions = labelOptions(noHide = TRUE)) %>%
addMarkers(lng = orlando_coords[2], lat = orlando_coords[1], label = "Orlando", labelOptions = labelOptions(noHide = TRUE)) %>%
addMarkers(lng = -93.59121, lat = 40.333101, labelOptions = labelOptions(noHide = TRUE), icon = WhoopingCraneIcon) %>%
addMarkers(lng = -108.2409, lat = 52.85146, labelOptions = labelOptions(noHide = TRUE), icon = WhoopingCraneIcon) %>%
addMarkers(lng = -95.311454, lat = 30.599285, labelOptions = labelOptions(noHide = TRUE), icon = WhoopingCraneIcon) %>%
addMarkers(lng = -84.900603, lat = 30.733441, labelOptions = labelOptions(noHide = TRUE), icon = WhoopingCraneIcon)
map
I used the OpenStreetMap and OpenTopoMap by ESRI for my base maps. I
then added my data points of Whooping Crane samples (2021-2024) that I
split into Canada (summer) and US (winter). I choose the colors for the
data points from a colorblind accessible palette. I added the United
States Annual Temperature Raster from USGS. I made this information into
a variable and added it to the map. I added layer control for the data
points and the temperature raster to have the option to remove them from
the map. I added elevation by first adding the elevatr package. The
elevation was already included in the OpenTopoMap, and all that needed
to be added was a legend to understand the color variations. To
determine the cities near the most observations, I zoomed in on the
biggest clusters. Once I found them, I googled their longitude and
latitude. I used those values to create a varible for eahc city. Then I
added markers for each of these cities, labeled with the city name.
Finally, I made an icon of a whooping crane (Grus americana). I added
the whooping crane icon throughout the migration path of the whooping
crane, from central Canada to the southern US.