Creating a species composition matrix for further analysis"

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(DivInsight)
data("Colombia")
library(vegan)

A species composition matrix can be created using data from a specific location. Species composition matrices are useful for many ecological analyses.

# use coordinates to clusterise data 
Colombia_coordinate_ref <- clusterise_sites(

  dataframe = 
    subset_by_coordinate_ref(
      dataframe = Colombia,
      coordinate_reference = c(-73.487520, 7.539986),
      distance_threshold = 50000
    ),

  cluster_min_length = 30 

)

site_regroup() can be used to group sites by a specified radius in metres. This method is a lot faster than running clusterise_sites() again with new parameters.

This will group, and therefore separate, sites that are further than 1km from one another.

# regroup sites with a radius of 1km
cref_1km <- site_regroup(

  clusterised_object = Colombia_coordinate_ref,
  regroup_radius = 1000

)

Species tables can be produced for each site using generate_spec_tables(). The number of individuals and species in each table can be specified using the min_individuals and min_species arguments.

Each table will consist of one row pertaining to the site and each column will be a species name. Each of these tables will be stored into a list.

cref_1km_spectables <- generate_spec_tables(

  clusterised_object = cref_1km,
  min_individuals = 30,
  min_species = 10

)

The name of each table can be viewed either by using names() or the $ operator.

The first number of each table name represents which group the site belongs to and the rest of the table name shows the date the individuals were observed.

Users should consider times between species tables, as well as seasonal changes, when choosing which tables to create their matrix.

Below we create a matrix using 18 sites from 18 different groups from mid-February to early-April in 2022.

# view the names of each table
print(names(cref_1km_spectables))

# store the chosen species tables into a single list 
species_table_list <- list(

  cref_1km_spectables$`17.2022-04-04`,
  cref_1km_spectables$`29.2022-04-02`,
  cref_1km_spectables$`16.2022-04-01`,
  cref_1km_spectables$`26.2022-03-31`,
  cref_1km_spectables$`1.2022-03-30`,

  cref_1km_spectables$`28.2022-03-29`,
  cref_1km_spectables$`18.2022-03-28`,
  cref_1km_spectables$`27.2022-03-26`,
  cref_1km_spectables$`9.2022-03-25`,
  cref_1km_spectables$`25.2022-03-23`,

  cref_1km_spectables$`8.2022-03-21`,
  cref_1km_spectables$`7.2022-03-19`,
  cref_1km_spectables$`24.2022-03-07`,
  cref_1km_spectables$`23.2022-03-06`,
  cref_1km_spectables$`19.2022-03-05`,

  cref_1km_spectables$`22.2022-02-27`,
  cref_1km_spectables$`21.2022-02-15`,
  cref_1km_spectables$`20.2022-02-14`

)     

# generate a species composition matrix
SCM1 <- generate_speccomm(species_table_list)

It is not necessary to change the row names of the matrix but We have the option to do so.

# change the row names of the matrix
SCM1 <- as.data.frame(SCM1)

row.names(SCM1) <- c(

  "17.2022-04-04",
  "29.2022-04-02",
  "16.2022-04-01",
  "26.2022-03-31",
  "1.2022-03-30",

  "28.2022-03-29",
  "18.2022-03-28",
  "27.2022-03-26",
  "9.2022-03-25",
  "25.2022-03-23",

  "8.2022-03-21",
  "7.2022-03-19",
  "24.2022-03-07",
  "23.2022-03-06",
  "19.2022-03-05",

  "22.2022-02-27",
  "21.2022-02-15",
  "20.2022-02-14"

)

SCM1 <- as.matrix(SCM1)

There are many analyses that can be done with a species composition matrix. Here a species accumulation curve using functions from the vegan package is demonstrated.

# create a species accumulation curve 
speccurve1 <- specaccum(SCM1, method = "random")

# plot the species accumulation curve
plot(speccurve1, ci.type="poly", 
     col="blue", 
     ci.col="lightblue",
     main = "Species accumulation curve for 18 Sites"
)

# view the predictions from the species accumulation curve
print(speccurve1)


Try the DivInsight package in your browser

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

DivInsight documentation built on Aug. 12, 2023, 9:06 a.m.