Background

Linking species occurrences and evolution to environmental variables and quantifying species โ€œnicheโ€ and its evolution is essential for many biogeographic questions. We will use the temperature range of species to reconstruct the evolution of temperature mean and variance using BITE tomorrow.

Objective

After this exercise, you will be able to extract environmental data from for geographic coordinates.

Exercise

  1. Download global environmental data from the CHELSA project or worldclim 2.
  2. Load the data into R and extract the mean annual temperature for your locations (raster, read_csv, extract)

Tutorial

Once you downloaded the environmental data, it is straightforward to extract values for geographic coordinates. The raster package will help you to handle environmental data in R and extract the values for your coordinates.

Load environmental data

library(raster)
library(tidyverse)

occ <- read_csv("example_data/input/occurrence_records_clean.csv")
env <- raster("example_data/input/wc2.0_bio_5m_01.tif")

Extract values

# Generate a spatial object with the coordinates
pts <- occ %>% select(decimalLongitude, decimalLatitude) %>% as.matrix()

# Extract the environmental values
ext <- raster::extract(env, pts) %>% enframe(name = NULL, value = "MAT")

# Bind coordinates and environmental variables
out <- bind_cols(occ, ext)

Write to disk

write_csv(out, "output/records+environment.csv")