Macroecological analysis at the species level

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.height = 5, 
  fig.width = 6,
  fig.align = 'center')

In another post, I have shown how to use letsR to analyze species traits at the community level. But, in many cases this type of analysis can lead to spurious patterns (click here for further discussion on this issue). An alternative can be analyzing the data at the species-level. In this post, I will show two examples on how to make macroecological analysis at the species level using the letsR package. In the first example, we will continue the test of Rapoport's rule on Phyllomedusa frogs using species centroids. In the second example, we will summarize climate spatial data at the species level to explore how temperature correlates with Phyllomedusa species extinction risk.

To start this test we can load our example PresenceAbsence object.

Note: I recommend to use the latest version of the letsR package on GitHub

# Load the package
library(letsR)

# Load the data
data("PAM")

# Plot
plot(PAM)

Example 1: Species level test of Rapoport's rule on Phyllomedusa frogs.

We first have to calculate species range size. We can do it directly on the species shapefiles for higher precision.

data("Phyllomedusa")
rangesize <- lets.rangesize(Phyllomedusa,
                            coordinates = "geographic")
rangesize <- rangesize / 1000 # Transform in km2

The second step is to calculate species geographical centroid/midpoint using the function lets.midpoint. There are several ways to calculate species geographic centroid, and this function offers several methods to do it. When species range are both circular and continuous, all of the methods will provide the same answer. However, as the shape of distributions start to become more complex, different methods will provide very different answers. For this example, we will use the default option "PC" (polygon centroid). This method will generate a polygon from the raster, and calculate the centroid of this polygon.

centroids <- lets.midpoint(PAM)
library(knitr)
library(dplyr)
library(kableExtra)
centroids
kable(centroids, "html") %>%
  kable_styling() %>%
  scroll_box(width = "600px", height = "400px")

We can also plot the geographical centroids.

d <- data.frame(centroids[, 2:3], 
                "Species" = centroids[, 1], 
                "Range size" = rangesize)
sp <- terra::vect(x = d, geom  = c("x", "y"))
plot(sp)
plot(sf::st_geometry(wrld_simpl), add = TRUE)

To check the Rapoport's rule we can plot the latitude against the range size:

library(ggplot2)
data_plot <- data.frame(centroids[, 2:3], "Range size" = rangesize)
g <- ggplot(data_plot, aes(x, Range_size))
g + geom_smooth() + geom_point() + labs(x = "Latitude(x)", y = "Range size")

Again, the data indicate that Rapoport's rule does not apply for Phyllomedusa genus. However, there seems to be an interesting pattern where range size decreases from the center towards the extremes of the group. This could be an effect of niche conservatism, where species in the extreme latitude would face very different conditions from the ancestral Phylllomedusa. Another possibility is that this pattern could be due to the shape of the continent, where extreme latitudes means smaller longitudes.

Example 2: Extinction risk correlation with temperature

To evaluate how temperature correlates with extinction risk, we first have to add the temperature variable to the PresenceAbsence object.

data(temp)
r <- terra::unwrap(temp)
PAM_env <- lets.addvar(PAM, r, fun = mean)

Next step is to get the average temperature values per species. The lets.summarizer can do this directly on the resulting object of lets.addvar function (note that this can only be done if onlyvar = FALSE). We only have to indicate the position of the variable in the matrix using the argument pos.

pos <- which(colnames(PAM_env) == "bio1_mean")
temp_mean <- lets.summarizer(PAM_env, pos)
temp_mean
kable(temp_mean, "html") %>%
  kable_styling() %>%
  scroll_box(width = "400px", height = "400px")

Following our example, we need to obtain the IUCN extinction risk data. Previous version of the package included functions to do this, but they are no longer supported. Luckily, there is a new package called rredlist that can do this for us. Yet, for now, we can use the example data in the letsR package called IUCN.

data("IUCN")
IUCN
kable(IUCN, "html") %>%
  kable_styling() %>%
  scroll_box(width = "800px", height = "400px")

Finally, we can verify the relationship between temperature and extinction risk.

level_order <- c("DD", "LC",  "EN", "CR") # ordering for the plot
data <- data.frame("Status" = factor(IUCN$Status, levels = level_order),
                   "Temperature" = temp_mean[, 2] / 10)
g <- ggplot(data, aes(Status, Temperature))
g + geom_boxplot() + coord_flip()

The graph indicate that there is a tendency for threatened Phyllomedusa species to occur in colder regions. Still, further statistical analysis should be done to confirm this pattern.

To cite letsR in publications use: Bruno Vilela and Fabricio Villalobos (2015). letsR: a new R package for data handling and analysis in macroecology. Methods in Ecology and Evolution. DOI: 10.1111/2041-210X.12401



Try the letsR package in your browser

Any scripts or data that you put into this service are public.

letsR documentation built on Nov. 23, 2023, 9:07 a.m.