knitr::opts_chunk$set(collapse = TRUE, comment = "#>", eval=F)
Load island data
# Load islands data data(largeislands, package="ggmap2")
Load bird species richness data
# Read bird data data(ter_birds_dist, package="rasterSp") # Add presence column ter_birds_dist$presence <- 1 # Calulate bird SR library(dplyr) sr_birds <- ter_birds_dist %>% group_by(x, y) %>% summarise(sum = sum(presence)) library(ggmap2) ggmap2(data=sr_birds, name="SR")
# Convert bird data to a spatial object sp::coordinates(sr_birds) <- ~x+y # Make sure both files have the same projection library(sp) proj4string(sr_birds) <- sf::st_crs(largeislands)$proj4string
Extract bird SR for each island
sr_birds <- raster::rasterFromXYZ(sr_birds) sr_islands <- raster::extract(sr_birds, largeislands, fun=sum, na.rm=FALSE, sp=TRUE) sr_islands <- sr_islands@data
Save data to file
write.csv(sr_islands, "sr_islands.csv", row.names=F)
Now, we can identify the 10 islands with the highest bird SR
library(dplyr) arrange(sr_islands, sum) %>% head(10) %>% select(NAME_ENGLI, Island) %>% unique()
# Convert bird data to a spatial object sp::coordinates(ter_birds_dist) <- ~x+y # Make sure both files have the same projection proj4string(ter_birds_dist) <- sf::st_crs(largeislands)$proj4string # SF approach # Turn ter_birds into sf object library(sf) ter_birds_dist <- st_as_sf(ter_birds_dist) island_birds <- ter_birds_dist[sf::st_within(ter_birds_dist, largeislands),] # Spatial approach # Turn large islands into an sp object #largeislands <- as(largeislands, "Spatial") # Extract bird names occuring on islands #island_birds <- sp::over(ter_birds_dist, largeislands) #island_birds_all <- cbind(ter_birds_dist@data, island_birds) #island_birds <- tidyr::drop_na(island_birds_all) # Only want to have unique names island_birds <- unique(island_birds$species) head(island_birds)
Save species names of birds that occur on islands to file
write.csv(island_birds, "island_birds.csv", row.names=F)
Load traitdata of birds
library(traitdata) data(globTherm)
Standardise species names of island_birds
# Read island birds island_birds <- read.csv("island_birds.csv") # Load standardised taxonomy load("data/taxonomyStd.rda") # Change species column of island birds colnames(island_birds) <- "scientificName" # Check which species have already a standardised taxonomy island_birds %>% left_join(taxonomyStd) # Add standardised taxonomy of remaining species #island_species <- traitdata::standardize_taxonomy(island_species, # return="scientificNameStd")
Merge island birds with globTherm
#Merge data island_birds_traits <- dplyr::full_join(island_species, globTherm, by="scientificNameStd")
Identify species that have certain traits
# number of unique species species_num <- length(unique(island_birds_traits$taxonomyStd)) # island species with maximum thermal tolerance species_tmax <- length(unique(island_birds_traits$taxonomyStd[which(!is.na(island_birds_traits$Tmax))]))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.