In the middle ground between science and superstition we dive into the weird. Here we seek out the weirdest combinations of species on Earth? Come join us as we work through this project. This readme file contains an overview and details of the project.
@BenMerSci
@afilazzola
@cdrobich
@scisus
Where is the weirdest combination of species on Earth?
## Load backend code for functions that generate transects
source("scripts//createTransects.r")
## dataframe of lat, lon for cities
cities <- data.frame(city = c("Toronto"),
lon = c(-79.3832),
lat = c(43.6532))
## Create transect for Toronto
torontoTransect <- cityTransect(citylon = cities$lon, citylat = cities$lat, nquadrat = 6, ## nquadrat is the number of quadrats
buffer=5, ## distance in km around the centroid of city to make the buffer. e.g. 5 = 10 x 10 km box with city as center
distance = 10) ## distance in km between buffered transects
## Plot transect
plot(canPoly[canPoly$NAME_1=="Ontario",], col="orange", ylim=c(41,45), xlim=c(-82,-76)) ## plot just Ontario, set x & y lim to zoom into Toronto area
plot(torontoTransect, add=T, col="blue")
## Save to file
saveRDS(torontoTransect, file = "data//transects//toronto.rds")
library(tidyverse)
library(rgbif)
#### Download data for transects
torQuadrat <- readRDS("data//transects//toronto.rds")
torQuadrat[1] ## look at polygons
## class : SpatialPolygons
## features : 1
## extent : -79.44528, -79.32112, 43.60815, 43.69825 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0
## Determine key for Canada
canCode <- isocodes[grep("Canada", isocodes$name), "code"]
occ_count(country=canCode) ## 71319394 occurrences in Canada
## [1] 71361505
## Download based on Quadrats
allquadrats <- data.frame()
for(i in 1:6){
quadratTemp <- occ_search(taxonKey = 6, country= canCode, hasCoordinate=T, return="data", ## select plants, in Canada, with coordinates
limit=50000, ## set limit for downloading records
geometry = wicket::sp_convert(torQuadrat[i])) ## specify first quadrat
quadratTemp[,"quadrat"] <- rep(i, nrow(quadratTemp))
allquadrats <- plyr::rbind.fill(allquadrats, quadratTemp)
print(i)
}
## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [1] 5
## [1] 6
## Drop columns with lots of NAs >20%
allquadrats <- allquadrats[,!apply(allquadrats, 2, function(x) sum(is.na(x))/nrow(allquadrats))>.20]
## Create species list for each quadrat with number of occurrences
speciesList <- allquadrats %>% group_by( quadrat, scientificName) %>% summarize(count=length(scientificName))
## Plot the output
summaryData <- speciesList %>% group_by(quadrat) %>% summarize(richness=length(scientificName), abundance=sum(count))
summaryLong <- summaryData %>% gather(response, value, 2:3)
ggplot(summaryLong, aes(x=quadrat, y=value)) + geom_bar(stat="identity") + facet_grid(response~., scales="free_y")