Loading occurence and raster data
mw_gbif <- occ_search(
scientificName = "Setophaga magnolia",
hasCoordinate = TRUE,
limit = 2000) $data
elevation = raster::getData("alt", country = "US")
## Warning in raster::getData("alt", country = "US"): getData will be removed in a future version of raster
## . Please use the geodata package instead
## returning a list of RasterLayer objects
elevation_can = raster::getData("alt", country = "CAN")
## Warning in raster::getData("alt", country = "CAN"): getData will be removed in a future version of raster
## . Please use the geodata package instead
elevation_mex = raster::getData("alt", country = "MEX")
## Warning in raster::getData("alt", country = "MEX"): getData will be removed in a future version of raster
## . Please use the geodata package instead
elevation = elevation[[1]]
temp = raster::getData("worldclim", var="tmax", res=5)
## Warning in raster::getData("worldclim", var = "tmax", res = 5): getData will be removed in a future version of raster
## . Please use the geodata package instead
temp = temp[[1]]
Filtering occurence data to improve visualization of species
migration
head(mw_gbif)
## # A tibble: 6 × 136
## key scientificName decimalLatitude decimalLongitude issues datasetKey
## <chr> <chr> <dbl> <dbl> <chr> <chr>
## 1 4510187721 Setophaga magno… 14.6 -90.5 cdc 50c9509d-…
## 2 4510148077 Setophaga magno… 17.4 -92.7 cdc,c… 50c9509d-…
## 3 4510142127 Setophaga magno… 18.4 -89.9 cdc,c… 50c9509d-…
## 4 4510153181 Setophaga magno… 18.3 -89.9 cdc,c… 50c9509d-…
## 5 4510160132 Setophaga magno… 18.2 -89.7 cdc,c… 50c9509d-…
## 6 4510482594 Setophaga magno… 17.5 -92.0 cdc,c… 50c9509d-…
## # ℹ 130 more variables: publishingOrgKey <chr>, installationKey <chr>,
## # hostingOrganizationKey <chr>, publishingCountry <chr>, protocol <chr>,
## # lastCrawled <chr>, lastParsed <chr>, crawlId <int>, basisOfRecord <chr>,
## # occurrenceStatus <chr>, taxonKey <int>, kingdomKey <int>, phylumKey <int>,
## # classKey <int>, orderKey <int>, familyKey <int>, genusKey <int>,
## # speciesKey <int>, acceptedTaxonKey <int>, acceptedScientificName <chr>,
## # kingdom <chr>, phylum <chr>, order <chr>, family <chr>, genus <chr>, …
mw_coords <- dplyr::rename(mw_gbif, latitude = decimalLatitude,
longitude = decimalLongitude) %>%
filter(longitude != 0, latitude !=0)
head(mw_coords)
## # A tibble: 6 × 136
## key scientificName latitude longitude issues datasetKey publishingOrgKey
## <chr> <chr> <dbl> <dbl> <chr> <chr> <chr>
## 1 45101877… Setophaga mag… 14.6 -90.5 cdc 50c9509d-… 28eb1a3f-1c15-4…
## 2 45101480… Setophaga mag… 17.4 -92.7 cdc,c… 50c9509d-… 28eb1a3f-1c15-4…
## 3 45101421… Setophaga mag… 18.4 -89.9 cdc,c… 50c9509d-… 28eb1a3f-1c15-4…
## 4 45101531… Setophaga mag… 18.3 -89.9 cdc,c… 50c9509d-… 28eb1a3f-1c15-4…
## 5 45101601… Setophaga mag… 18.2 -89.7 cdc,c… 50c9509d-… 28eb1a3f-1c15-4…
## 6 45104825… Setophaga mag… 17.5 -92.0 cdc,c… 50c9509d-… 28eb1a3f-1c15-4…
## # ℹ 129 more variables: installationKey <chr>, hostingOrganizationKey <chr>,
## # publishingCountry <chr>, protocol <chr>, lastCrawled <chr>,
## # lastParsed <chr>, crawlId <int>, basisOfRecord <chr>,
## # occurrenceStatus <chr>, taxonKey <int>, kingdomKey <int>, phylumKey <int>,
## # classKey <int>, orderKey <int>, familyKey <int>, genusKey <int>,
## # speciesKey <int>, acceptedTaxonKey <int>, acceptedScientificName <chr>,
## # kingdom <chr>, phylum <chr>, order <chr>, family <chr>, genus <chr>, …
mw_wintering <-filter(mw_coords,month=="1"|month=="2"|month=="3"|month=="4") %>%
filter()
head(mw_wintering)
## # A tibble: 6 × 136
## key scientificName latitude longitude issues datasetKey publishingOrgKey
## <chr> <chr> <dbl> <dbl> <chr> <chr> <chr>
## 1 45101877… Setophaga mag… 14.6 -90.5 cdc 50c9509d-… 28eb1a3f-1c15-4…
## 2 45101480… Setophaga mag… 17.4 -92.7 cdc,c… 50c9509d-… 28eb1a3f-1c15-4…
## 3 45101421… Setophaga mag… 18.4 -89.9 cdc,c… 50c9509d-… 28eb1a3f-1c15-4…
## 4 45101531… Setophaga mag… 18.3 -89.9 cdc,c… 50c9509d-… 28eb1a3f-1c15-4…
## 5 45101601… Setophaga mag… 18.2 -89.7 cdc,c… 50c9509d-… 28eb1a3f-1c15-4…
## 6 45104825… Setophaga mag… 17.5 -92.0 cdc,c… 50c9509d-… 28eb1a3f-1c15-4…
## # ℹ 129 more variables: installationKey <chr>, hostingOrganizationKey <chr>,
## # publishingCountry <chr>, protocol <chr>, lastCrawled <chr>,
## # lastParsed <chr>, crawlId <int>, basisOfRecord <chr>,
## # occurrenceStatus <chr>, taxonKey <int>, kingdomKey <int>, phylumKey <int>,
## # classKey <int>, orderKey <int>, familyKey <int>, genusKey <int>,
## # speciesKey <int>, acceptedTaxonKey <int>, acceptedScientificName <chr>,
## # kingdom <chr>, phylum <chr>, order <chr>, family <chr>, genus <chr>, …
mw_breeding <-filter(mw_coords,month=="5"|month=="6"|month=="7"|month=="8"|month=="9")
head(mw_breeding)
## # A tibble: 6 × 136
## key scientificName latitude longitude issues datasetKey publishingOrgKey
## <chr> <chr> <dbl> <dbl> <chr> <chr> <chr>
## 1 41031863… Setophaga mag… 25.6 -80.3 cdc,c… 50c9509d-… 28eb1a3f-1c15-4…
## 2 41029454… Setophaga mag… 25.2 -80.3 cdc,c… 50c9509d-… 28eb1a3f-1c15-4…
## 3 41034323… Setophaga mag… 25.2 -80.3 cdc,c… 50c9509d-… 28eb1a3f-1c15-4…
## 4 41031853… Setophaga mag… 26.2 -97.7 cdc,c… 50c9509d-… 28eb1a3f-1c15-4…
## 5 41117987… Setophaga mag… 29.6 -94.4 cdc,c… 50c9509d-… 28eb1a3f-1c15-4…
## 6 41030443… Setophaga mag… 32.8 -97.2 cdc,c… 50c9509d-… 28eb1a3f-1c15-4…
## # ℹ 129 more variables: installationKey <chr>, hostingOrganizationKey <chr>,
## # publishingCountry <chr>, protocol <chr>, lastCrawled <chr>,
## # lastParsed <chr>, crawlId <int>, basisOfRecord <chr>,
## # occurrenceStatus <chr>, taxonKey <int>, kingdomKey <int>, phylumKey <int>,
## # classKey <int>, orderKey <int>, familyKey <int>, genusKey <int>,
## # speciesKey <int>, acceptedTaxonKey <int>, acceptedScientificName <chr>,
## # kingdom <chr>, phylum <chr>, order <chr>, family <chr>, genus <chr>, …
Establishing points for three populous cities
rating <- 1:3
city <- c('New York', 'Philadelphia', 'Toronto')
latitude <- c("40.730610","39.9526","43.6532")
longitude <- c("-74.0060","-75.1652","-79.3832")
pop_cities <- data.frame(city,latitude,longitude,stringsAsFactors = FALSE)
pop_cities$latitude = as.numeric(pop_cities$latitude)
pop_cities$longitude = as.numeric(pop_cities$longitude)
st_as_sf(pop_cities, coords = c("longitude", "latitude"), crs = 4326)
## Simple feature collection with 3 features and 1 field
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -79.3832 ymin: 39.9526 xmax: -74.006 ymax: 43.6532
## Geodetic CRS: WGS 84
## city geometry
## 1 New York POINT (-74.006 40.73061)
## 2 Philadelphia POINT (-75.1652 39.9526)
## 3 Toronto POINT (-79.3832 43.6532)
Leaflet mapping
pal <- colorNumeric(c("burlywood4", "lemonchiffon3", "lemonchiffon"), raster::values(elevation),na.color = "transparent")
pal2 <- colorNumeric(c("deepskyblue3","cadetblue", "darkseagreen","khaki", "darkgoldenrod","darkorange4"), raster::values(temp) ,na.color = "transparent")
mw_map <- leaflet() %>%
setView(lng = -79, lat = 30, zoom = 2.8) %>%
addRasterImage(temp, colors = pal2, opacity = 0.4, maxBytes = 10799709, group = "Temperature") %>%
addRasterImage(elevation, colors = pal, opacity = 0.5, maxBytes = 10052582, group = "Elevation") %>%
addRasterImage(elevation_can, colors = pal, opacity = 0.5, maxBytes = 15248135, group = "Elevation") %>%
addLegend(pal = pal, values = raster::values(elevation), title = "Elevation") %>%
addRasterImage(elevation_mex, colors = pal, opacity = 0.5, group = "Elevation") %>%
addTiles() %>%
addCircleMarkers(data = mw_breeding,
~longitude, ~latitude,
color = "goldenrod", fillOpacity = 1, radius = 2.5, stroke = FALSE,
popup = ~paste(species, "<br>", eventDate,"<br>",stateProvince),
group="Magnolia Warbler (Setophaga magnolia)") %>%
addCircleMarkers(data = mw_wintering,
~longitude, ~latitude,
color = "darkslategrey", fillOpacity = 1, radius = 2.5, stroke = FALSE,
popup = ~paste(species, "<br>", eventDate,"<br>",stateProvince),
group="Magnolia Warbler (Setophaga magnolia)") %>%
addMarkers(data = pop_cities,
~longitude, ~latitude,
icon = list(
iconUrl = 'https://icons.iconarchive.com/icons/picol/picol/256/Star-icon.png',
iconSize = c(7, 7)),
popup = ~as.character(city),
group="Populous Cities") %>%
addLayersControl(overlayGroups = c("Populous Cities","Magnolia Warbler (Setophaga magnolia)","Elevation","Temperature"),
options = layersControlOptions(collapsed = FALSE)) %>%
addLegend(position = "bottomleft",
colors = "goldenrod",
labels = c("Breeding Period"),
opacity = 1) %>%
addLegend(position = "bottomleft",
colors = "darkslategrey",
labels = c("Wintering Period"),
opacity = 1)
## Warning in colors(.): Some values were outside the color scale and will be
## treated as NA
## Warning in colors(.): Some values were outside the color scale and will be
## treated as NA
mw_map