library(knitr)
library(ggplot2)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ lubridate 1.9.3 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.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)
I will be using blue jay data from the eBird observation dataset. Since 943k observations is not possible for me to be computing with my laptop, I will use a sample of 1000 to demonstrate the process.
# we run this once and only once
#bird_gbif_full <- readr::read_delim("0007786-240229165702484.csv", delim = "\t", escape_double = FALSE,
# col_names = TRUE, na = c("", "NA"))
# now we take a small sample
#bird_gbif <- bird_gbif_full[sample(nrow(bird_gbif_full), 1000), ]
#write.csv(bird_gbif, "sampled_bird_gbif.csv", row.names = FALSE)
bird_gbif <- read.csv("sampled_bird_gbif.csv")
# checking all 50 of these columns.
head(bird_gbif)
## gbifID datasetKey
## 1 1189503624 4fa7b334-ce0d-4e88-aaae-2e0c138d049e
## 2 4249149979 4fa7b334-ce0d-4e88-aaae-2e0c138d049e
## 3 2186337886 4fa7b334-ce0d-4e88-aaae-2e0c138d049e
## 4 3588877598 4fa7b334-ce0d-4e88-aaae-2e0c138d049e
## 5 4371530741 4fa7b334-ce0d-4e88-aaae-2e0c138d049e
## 6 3622315879 4fa7b334-ce0d-4e88-aaae-2e0c138d049e
## occurrenceID kingdom phylum class
## 1 URN:catalog:CLO:EBIRD:OBS273849410 Animalia Chordata Aves
## 2 URN:catalog:CLO:EBIRD:OBS1413838573 Animalia Chordata Aves
## 3 URN:catalog:CLO:EBIRD:OBS658213190 Animalia Chordata Aves
## 4 URN:catalog:CLO:EBIRD:OBS1126548670 Animalia Chordata Aves
## 5 URN:catalog:CLO:EBIRD:OBS1465937488 Animalia Chordata Aves
## 6 URN:catalog:CLO:EBIRD_ATL_NY:OBS1136661448 Animalia Chordata Aves
## order family genus species infraspecificEpithet
## 1 Passeriformes Corvidae Cyanocitta Cyanocitta cristata NA
## 2 Passeriformes Corvidae Cyanocitta Cyanocitta cristata NA
## 3 Passeriformes Corvidae Cyanocitta Cyanocitta cristata NA
## 4 Passeriformes Corvidae Cyanocitta Cyanocitta cristata NA
## 5 Passeriformes Corvidae Cyanocitta Cyanocitta cristata NA
## 6 Passeriformes Corvidae Cyanocitta Cyanocitta cristata NA
## taxonRank scientificName verbatimScientificName
## 1 SPECIES Cyanocitta cristata (Linnaeus, 1758) Cyanocitta cristata
## 2 SPECIES Cyanocitta cristata (Linnaeus, 1758) Cyanocitta cristata
## 3 SPECIES Cyanocitta cristata (Linnaeus, 1758) Cyanocitta cristata
## 4 SPECIES Cyanocitta cristata (Linnaeus, 1758) Cyanocitta cristata
## 5 SPECIES Cyanocitta cristata (Linnaeus, 1758) Cyanocitta cristata
## 6 SPECIES Cyanocitta cristata (Linnaeus, 1758) Cyanocitta cristata
## verbatimScientificNameAuthorship countryCode
## 1 NA US
## 2 NA CA
## 3 NA US
## 4 NA US
## 5 NA US
## 6 NA US
## locality stateProvince occurrenceStatus
## 1 Leslie Moses Park Oklahoma PRESENT
## 2 Starwood Drive, Guelph Ontario PRESENT
## 3 Arcadia Marsh Michigan PRESENT
## 4 Elizabeth Hartwell Mason Neck NWR Virginia PRESENT
## 5 Kings Creek Village Florida PRESENT
## 6 168 GSR - Yard to Mailbox New York PRESENT
## individualCount publishingOrgKey decimalLatitude
## 1 2 e2e717bf-551a-4917-bdc9-4fa0f342c530 35.28196
## 2 1 e2e717bf-551a-4917-bdc9-4fa0f342c530 43.56566
## 3 1 e2e717bf-551a-4917-bdc9-4fa0f342c530 44.48890
## 4 1 e2e717bf-551a-4917-bdc9-4fa0f342c530 38.64061
## 5 3 e2e717bf-551a-4917-bdc9-4fa0f342c530 25.69399
## 6 6 e2e717bf-551a-4917-bdc9-4fa0f342c530 42.36821
## decimalLongitude coordinateUncertaintyInMeters coordinatePrecision elevation
## 1 -96.24899 NA NA NA
## 2 -80.21234 NA NA NA
## 3 -86.22859 NA NA NA
## 4 -77.16367 NA NA NA
## 5 -80.32806 NA NA NA
## 6 -76.36652 NA NA NA
## elevationAccuracy depth depthAccuracy eventDate day month year taxonKey
## 1 NA NA NA 2014-09-28 28 9 2014 2482593
## 2 NA NA NA 2022-05-03 3 5 2022 2482593
## 3 NA NA NA 2018-09-17 17 9 2018 2482593
## 4 NA NA NA 2021-04-18 18 4 2021 2482593
## 5 NA NA NA 2022-06-24 24 6 2022 2482593
## 6 NA NA NA 2021-04-30 30 4 2021 2482593
## speciesKey basisOfRecord institutionCode collectionCode catalogNumber
## 1 2482593 HUMAN_OBSERVATION CLO EBIRD OBS273849410
## 2 2482593 HUMAN_OBSERVATION CLO EBIRD OBS1413838573
## 3 2482593 HUMAN_OBSERVATION CLO EBIRD OBS658213190
## 4 2482593 HUMAN_OBSERVATION CLO EBIRD OBS1126548670
## 5 2482593 HUMAN_OBSERVATION CLO EBIRD OBS1465937488
## 6 2482593 HUMAN_OBSERVATION CLO EBIRD_ATL_NY OBS1136661448
## recordNumber identifiedBy dateIdentified license rightsHolder recordedBy
## 1 NA NA NA CC_BY_4_0 NA obsr422243
## 2 NA NA NA CC_BY_4_0 NA obsr281598
## 3 NA NA NA CC_BY_4_0 NA obsr438648
## 4 NA NA NA CC_BY_4_0 NA obsr955967
## 5 NA NA NA CC_BY_4_0 NA obsr152076
## 6 NA NA NA CC_BY_4_0 NA obsr9009
## typeStatus establishmentMeans lastInterpreted mediaType
## 1 NA NA 2024-01-24 21:33:16.367 NA
## 2 NA NA 2024-01-24 21:51:28.362 NA
## 3 NA NA 2024-01-24 21:38:42.638 NA
## 4 NA NA 2024-01-24 20:53:54.198 NA
## 5 NA NA 2024-01-24 21:27:27.26 NA
## 6 NA NA 2024-01-24 20:54:08.557 NA
## issue
## 1 CONTINENT_DERIVED_FROM_COORDINATES;TAXON_MATCH_TAXON_CONCEPT_ID_IGNORED
## 2 CONTINENT_DERIVED_FROM_COORDINATES;TAXON_MATCH_TAXON_CONCEPT_ID_IGNORED
## 3 CONTINENT_DERIVED_FROM_COORDINATES;TAXON_MATCH_TAXON_CONCEPT_ID_IGNORED
## 4 CONTINENT_DERIVED_FROM_COORDINATES;TAXON_MATCH_TAXON_CONCEPT_ID_IGNORED
## 5 CONTINENT_DERIVED_FROM_COORDINATES;TAXON_MATCH_TAXON_CONCEPT_ID_IGNORED
## 6 CONTINENT_DERIVED_FROM_COORDINATES;TAXON_MATCH_TAXON_CONCEPT_ID_IGNORED
# renaming "decimalLatitude" & "decimalLongitude" (btw you can really only run this once)
bird_gbif <- dplyr::rename(bird_gbif, latitude = decimalLatitude, longitude = decimalLongitude)
# head again just in case
head(bird_gbif)
## gbifID datasetKey
## 1 1189503624 4fa7b334-ce0d-4e88-aaae-2e0c138d049e
## 2 4249149979 4fa7b334-ce0d-4e88-aaae-2e0c138d049e
## 3 2186337886 4fa7b334-ce0d-4e88-aaae-2e0c138d049e
## 4 3588877598 4fa7b334-ce0d-4e88-aaae-2e0c138d049e
## 5 4371530741 4fa7b334-ce0d-4e88-aaae-2e0c138d049e
## 6 3622315879 4fa7b334-ce0d-4e88-aaae-2e0c138d049e
## occurrenceID kingdom phylum class
## 1 URN:catalog:CLO:EBIRD:OBS273849410 Animalia Chordata Aves
## 2 URN:catalog:CLO:EBIRD:OBS1413838573 Animalia Chordata Aves
## 3 URN:catalog:CLO:EBIRD:OBS658213190 Animalia Chordata Aves
## 4 URN:catalog:CLO:EBIRD:OBS1126548670 Animalia Chordata Aves
## 5 URN:catalog:CLO:EBIRD:OBS1465937488 Animalia Chordata Aves
## 6 URN:catalog:CLO:EBIRD_ATL_NY:OBS1136661448 Animalia Chordata Aves
## order family genus species infraspecificEpithet
## 1 Passeriformes Corvidae Cyanocitta Cyanocitta cristata NA
## 2 Passeriformes Corvidae Cyanocitta Cyanocitta cristata NA
## 3 Passeriformes Corvidae Cyanocitta Cyanocitta cristata NA
## 4 Passeriformes Corvidae Cyanocitta Cyanocitta cristata NA
## 5 Passeriformes Corvidae Cyanocitta Cyanocitta cristata NA
## 6 Passeriformes Corvidae Cyanocitta Cyanocitta cristata NA
## taxonRank scientificName verbatimScientificName
## 1 SPECIES Cyanocitta cristata (Linnaeus, 1758) Cyanocitta cristata
## 2 SPECIES Cyanocitta cristata (Linnaeus, 1758) Cyanocitta cristata
## 3 SPECIES Cyanocitta cristata (Linnaeus, 1758) Cyanocitta cristata
## 4 SPECIES Cyanocitta cristata (Linnaeus, 1758) Cyanocitta cristata
## 5 SPECIES Cyanocitta cristata (Linnaeus, 1758) Cyanocitta cristata
## 6 SPECIES Cyanocitta cristata (Linnaeus, 1758) Cyanocitta cristata
## verbatimScientificNameAuthorship countryCode
## 1 NA US
## 2 NA CA
## 3 NA US
## 4 NA US
## 5 NA US
## 6 NA US
## locality stateProvince occurrenceStatus
## 1 Leslie Moses Park Oklahoma PRESENT
## 2 Starwood Drive, Guelph Ontario PRESENT
## 3 Arcadia Marsh Michigan PRESENT
## 4 Elizabeth Hartwell Mason Neck NWR Virginia PRESENT
## 5 Kings Creek Village Florida PRESENT
## 6 168 GSR - Yard to Mailbox New York PRESENT
## individualCount publishingOrgKey latitude longitude
## 1 2 e2e717bf-551a-4917-bdc9-4fa0f342c530 35.28196 -96.24899
## 2 1 e2e717bf-551a-4917-bdc9-4fa0f342c530 43.56566 -80.21234
## 3 1 e2e717bf-551a-4917-bdc9-4fa0f342c530 44.48890 -86.22859
## 4 1 e2e717bf-551a-4917-bdc9-4fa0f342c530 38.64061 -77.16367
## 5 3 e2e717bf-551a-4917-bdc9-4fa0f342c530 25.69399 -80.32806
## 6 6 e2e717bf-551a-4917-bdc9-4fa0f342c530 42.36821 -76.36652
## coordinateUncertaintyInMeters coordinatePrecision elevation elevationAccuracy
## 1 NA NA NA NA
## 2 NA NA NA NA
## 3 NA NA NA NA
## 4 NA NA NA NA
## 5 NA NA NA NA
## 6 NA NA NA NA
## depth depthAccuracy eventDate day month year taxonKey speciesKey
## 1 NA NA 2014-09-28 28 9 2014 2482593 2482593
## 2 NA NA 2022-05-03 3 5 2022 2482593 2482593
## 3 NA NA 2018-09-17 17 9 2018 2482593 2482593
## 4 NA NA 2021-04-18 18 4 2021 2482593 2482593
## 5 NA NA 2022-06-24 24 6 2022 2482593 2482593
## 6 NA NA 2021-04-30 30 4 2021 2482593 2482593
## basisOfRecord institutionCode collectionCode catalogNumber recordNumber
## 1 HUMAN_OBSERVATION CLO EBIRD OBS273849410 NA
## 2 HUMAN_OBSERVATION CLO EBIRD OBS1413838573 NA
## 3 HUMAN_OBSERVATION CLO EBIRD OBS658213190 NA
## 4 HUMAN_OBSERVATION CLO EBIRD OBS1126548670 NA
## 5 HUMAN_OBSERVATION CLO EBIRD OBS1465937488 NA
## 6 HUMAN_OBSERVATION CLO EBIRD_ATL_NY OBS1136661448 NA
## identifiedBy dateIdentified license rightsHolder recordedBy typeStatus
## 1 NA NA CC_BY_4_0 NA obsr422243 NA
## 2 NA NA CC_BY_4_0 NA obsr281598 NA
## 3 NA NA CC_BY_4_0 NA obsr438648 NA
## 4 NA NA CC_BY_4_0 NA obsr955967 NA
## 5 NA NA CC_BY_4_0 NA obsr152076 NA
## 6 NA NA CC_BY_4_0 NA obsr9009 NA
## establishmentMeans lastInterpreted mediaType
## 1 NA 2024-01-24 21:33:16.367 NA
## 2 NA 2024-01-24 21:51:28.362 NA
## 3 NA 2024-01-24 21:38:42.638 NA
## 4 NA 2024-01-24 20:53:54.198 NA
## 5 NA 2024-01-24 21:27:27.26 NA
## 6 NA 2024-01-24 20:54:08.557 NA
## issue
## 1 CONTINENT_DERIVED_FROM_COORDINATES;TAXON_MATCH_TAXON_CONCEPT_ID_IGNORED
## 2 CONTINENT_DERIVED_FROM_COORDINATES;TAXON_MATCH_TAXON_CONCEPT_ID_IGNORED
## 3 CONTINENT_DERIVED_FROM_COORDINATES;TAXON_MATCH_TAXON_CONCEPT_ID_IGNORED
## 4 CONTINENT_DERIVED_FROM_COORDINATES;TAXON_MATCH_TAXON_CONCEPT_ID_IGNORED
## 5 CONTINENT_DERIVED_FROM_COORDINATES;TAXON_MATCH_TAXON_CONCEPT_ID_IGNORED
## 6 CONTINENT_DERIVED_FROM_COORDINATES;TAXON_MATCH_TAXON_CONCEPT_ID_IGNORED
bird_gbif %>% drop_na(countryCode) %>% count(countryCode, sort = TRUE) %>% ggplot(aes(x = reorder(countryCode,
n), y = n, fill = countryCode)) + geom_bar(stat = "identity", show.legend = FALSE) +
labs(x = "Country", y = "Number of Observances") + coord_flip()
# a very US dominated map. our sample also seems to have a eastward bias.
bird_gbif %>% drop_na(month) %>% count(month, sort = TRUE) %>% ggplot(aes(x = reorder(month,
n), y = n, fill = month)) + geom_bar(stat = "identity", show.legend = FALSE, fill="darkgrey") +
labs(x = "month", y = "Number of Observances") + coord_flip()
# 5 is assumably May, and it displays a large amount of observances.
Figuring out
bird_gbif %>% count(stateProvince, sort = TRUE)
## stateProvince n
## 1 Ontario 81
## 2 New York 78
## 3 Quebec 60
## 4 Michigan 53
## 5 Pennsylvania 52
## 6 Florida 45
## 7 Massachusetts 43
## 8 Ohio 41
## 9 Texas 40
## 10 Wisconsin 39
## 11 Maryland 36
## 12 Virginia 32
## 13 Illinois 30
## 14 Colorado 29
## 15 New Jersey 29
## 16 North Carolina 26
## 17 Vermont 23
## 18 Maine 21
## 19 Minnesota 21
## 20 Connecticut 18
## 21 Georgia 16
## 22 New Hampshire 16
## 23 Tennessee 15
## 24 Indiana 14
## 25 Louisiana 14
## 26 Alabama 13
## 27 Arkansas 13
## 28 Kansas 13
## 29 Kentucky 10
## 30 Alberta 9
## 31 Oklahoma 9
## 32 Iowa 8
## 33 Manitoba 7
## 34 Missouri 7
## 35 South Carolina 7
## 36 Nova Scotia 6
## 37 Delaware 4
## 38 Mississippi 4
## 39 Nebraska 4
## 40 Rhode Island 3
## 41 West Virginia 3
## 42 District of Columbia 2
## 43 New Brunswick 2
## 44 Montana 1
## 45 Newfoundland and Labrador 1
## 46 North Dakota 1
## 47 Saskatchewan 1
#new york, ontario, and quebec are the 3 state/provinces with the most observances
#NYC is the most populous city in NY
#Toronto is the most populous city in Ontario
#Montreal is the most populous city in Quebec
#cutting the months into bins that i can use to display seasons, since most if not all of the data is from the northern hemisphere
bird_gbif$Season <- cut(bird_gbif$month,
c(0, 3, 6, 9, 12), include.lowest = TRUE,
labels = c('Winter', 'Spring', 'Summer', 'Fall'))
seasonCol <- colorFactor(palette = 'viridis', bird_gbif$Season)
#making a dataframe of the 3 major cities with manually determined coords
majorcities <- data.frame(
"latitude" = c(40.7128,43.6532,45.5019), "longitude" = c(-74.0060,-79.3832,-73.5674),
City = c("New York City","Toronto","Montreal") )
# testing a map
attempt <- leaflet::leaflet(bird_gbif) %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addCircleMarkers(~longitude, ~latitude, color = ~seasonCol(Season), stroke = FALSE) %>%
addMarkers(data=majorcities, ~longitude, ~latitude, popup = majorcities$City) %>%
addLegend('bottomright', pal = seasonCol, values = bird_gbif$Season,
title = 'Season of observation',
opacity = 1)
attempt
I wanted to make a map that displayed the seasons that observations were taken in, and where they were taken. The transparent dots would allow us to get a colored image of where most observations were in each season. To simplify things, we can make it 2 colors, one during migration season, one during nesting season. This would allow us to differentiate the frequency of sightings.