knitr::opts_chunk$set( collapse = TRUE, comment = "#>", results="asis", warning=F, message=F, fig.width=10, fig.height=8 )
# Load packages library(dplyr); library(magrittr); library(tidyr) library(ggplot2); library(patchwork) library(sf); library(sp) # Load edc package library(edc) # Load shapefile of Europe data("europe", package="edc")
data("hochkirch_orthoptera_eur") #head(hochkirch_orthoptera_eur)
This dataset contains 5 columns with the following names:
binomial, presence, origin, seasonal, geometry
Here each of these columns is explained:
geometry gives you the shape geometry of the species
binomial gives you the name of the respective species
presence, origin and seasonal are additional information about the distribution of a species:
presence describes the degree of certainty of the existence of a species in a certain region
origin describes, if the species has its native origin in a certain region
seasonal describes beschreibt den Zeitraum im Lebenszyklus der Art, in dem sie in einem Gebiet vorkommt.
More details on the presence, origin and seasonal information can be found below or here: http://datazone.birdlife.org/species/spcdistPOS
Note: Because of the additional information (presence, origin und seasonal), it can be that there are multiple values for one species at one location. Before you use the data, you might have to filter()/subset() the data or summarise() the perc_present column in order to use it.
1 = Extant: The species is known or thought very likely to occur presently in the area, usually encompassing current or recent localities where suitable habitat at appropriate altitudes remains.
2 = Probably Extant: The species’ presence is considered probable, either based on extrapolations of known records, or realistic inferences (e.g., based on distribution of suitable habitat at appropriate altitudes and proximity to areas where it is known or thought very likely to remain Extant). ‘Probably Extant’ ranges often extend beyond areas where the species is Extant, or may fall between them.
3 = Possibly Extant: The species may possibly occur, based on the distribution of suitable habitat at appropriate altitudes, but where there are no known records. ‘Possibly Extant’ ranges often extend beyond areas where the species is Extant (q.v.) or Probably Extant (q.v.), or may fall between them.
4 = Possibly Extinct: The species was formerly known or thought very likely to occur in the area, but it is most likely now extirpated from the area because habitat loss/other threats are thought likely to have extirpated the species and/or owing to a lack of records in the last 30 years.
5 = Extinct (post 1500): The species was formerly known or thought very likely to occur in the area, but there have been no records in the last 30 years and it is almost certain that the species no longer occurs, and/or habitat loss/other threats have almost certainly extirpated the species.
6 = Presence Uncertain: The species was formerly known or thought very likely to occur in the area but it is no longer known whether it still occurs (usually because there have been no recent surveys).
1 = Native: The species is/was native to the area
2 = Reintroduced: The species is/was reintroduced through either direct or indirect human activity
3 = Introduced: The species is/was introduced outside of its historical distribution range through either direct or indirect human activity.
4 = Vagrant: The species is/was recorded once or sporadically, but it is known not to be native to the area.
5 = Origin Uncertain: The species’ provenance in an area is not known (it may be native, reintroduced or introduced).
1 = Resident: The species is/was known or thought very likely to be resident throughout the year
2 = Breeding Season: The species is/was known or thought very likely to occur regularly during the breeding season and to breed.
3 = Non-breeding Season: The species is/was known or thought very likely to occur regularly during the non-breeding season. In the Eurasian and North American contexts, this encompasses ‘winter’.
4 = Passage: The species is/was known or thought very likely to occur regularly during a relatively short period(s) of the year on migration between breeding and non-breeding ranges.
5 = Seasonal occurence uncertain: The species is/was present, but it is not known if it is present during part or all of the year.
data("kalkman_odonata_eur") #head(kalkman_odonata_eur)
This dataset contains 5 columns with the following names:
Country, Latitude, Longitude, MGRS WGS84, Period
In addition, there is a column for every species indicating if the species is present (1) or not (0) in a given grid cell for a given period.
# Read Euro-Cordex climate data data("cordex_bioclim_eur_p44deg") # Split data by scenario and timeframe to be able to use rasterFromXYZ groupkeys <- cordex_bioclim_eur_p44deg %>% tidyr::unite(col="gcm_rcm_rcp", c("gcm", "ensemble", "rcm", "rs", "rcp"), sep="_") %>% group_by(gcm_rcm_rcp, time_frame) %>% group_keys() cordex_bioclim_eur_p44deg <- cordex_bioclim_eur_p44deg %>% tidyr::unite(col="gcm_rcm_rcp", c("gcm", "ensemble", "rcm", "rs", "rcp"), sep="_") %>% group_split(gcm_rcm_rcp, time_frame) #' The rasterFromXYZ function requires that your data.frame is structured in a very specific way, #' i.e. first column is x, second column is y and the remaining columns can only be numeric variables. # Turn data into raster r_bioclim <- lapply(cordex_bioclim_eur_p44deg, raster::rasterFromXYZ) #raster::plot(r_bioclim[[1]][[1]]) #plot(sf::st_geometry(europe), add=T) #r_bioclim[[1]] #' Data has no CRS # Define CRS (WGS84) r_bioclim <- lapply(r_bioclim, function(x){ raster::crs(x) <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" return(x) }) #r_bioclim[[1]] #' Now data has correct CRS
# Extract climate data for Acheta hispanicus ortho_bioclim <- lapply(1:length(r_bioclim), function(x){ raster::extract(x=r_bioclim[[x]], y=as(hochkirch_orthoptera_eur %>% filter(BINOMIAL == "Acheta hispanicus"), "Spatial")) %>% as.data.frame() %>% mutate(gcm_rcm_rcp=groupkeys$gcm_rcm_rcp[x], time_frame=groupkeys$time_frame[x]) }) ortho_bioclim <- bind_rows(ortho_bioclim) %>% drop_na() #head(ortho_bioclim) #summary(ortho_bioclim) ortho_bioclim %>% filter(gcm_rcm_rcp == "ICHEC-EC-EARTH_r1i1p1_KNMI-RACMO22E_v1_rcp45") %>% select(time_frame, bio1:bio19) %>% ggplot() + geom_violin(aes(x=time_frame, y=bio1)) + labs(x="Presence", y="bio1", title="Acheta hispanicus")
# Turn Odonata data into Spatial Points sf_odonata <- sf::st_as_sf(kalkman_odonata_eur, coords = c("Longitude", "Latitude"), crs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") # Plot data of Ophiogomphus cecilia plot(sf::st_geometry(sf_odonata %>% select("Ophiogomphus cecilia"))) plot(sf::st_geometry(europe), add=T) # Extract climate data for Odonata data odo_bioclim <- lapply(1:length(r_bioclim), function(x){ raster::extract(r_bioclim[[x]], sf_odonata, sp=T) %>% as.data.frame() %>% select(-c(Country, `MGRS.WGS84`)) %>% mutate(gcm_rcm_rcp=groupkeys$gcm_rcm_rcp[x], time_frame=groupkeys$time_frame[x]) }) odo_bioclim <- bind_rows(odo_bioclim) #head(odo_bioclim) #summary(odo_bioclim) p1 <- odo_bioclim %>% filter(gcm_rcm_rcp == "ICHEC-EC-EARTH_r1i1p1_KNMI-RACMO22E_v1_rcp45", time_frame== "1991-2020", Period ==">1990") %>% select(coords.x1, coords.x2, bio1:bio19, Aeshna.cyanea) %>% ggplot() + geom_violin(aes(x=as.factor(Aeshna.cyanea), y=bio1)) + labs(x="Presence", y="bio1", title="Aeshna cyanea") + theme_bw() p2 <- odo_bioclim %>% filter(gcm_rcm_rcp == "ICHEC-EC-EARTH_r1i1p1_KNMI-RACMO22E_v1_rcp45", time_frame== "1991-2020", Period ==">1990") %>% select(coords.x1, coords.x2, bio1:bio19, Aeshna.cyanea) %>% ggplot() + geom_violin(aes(x=as.factor(Aeshna.cyanea), y=bio1)) + labs(x="Presence", y="bio12", title="Aeshna cyanea") + theme_bw() p1 + p2 rm(list=ls()); gc()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.