download.file(
url = "https://kamapu.gitlab.io/multivar/data/course-data.zip",
destfile = "course-data.zip", method = "curl")
unzip("course-data.zip", overwrite = TRUE)
unlink("course-data.zip")
Assets
Download Data
A zip file with the data sets required for the R sessions can be downloaded here.
Alternatively, you load the data in your working directory by running following code in your R session:
Required Packages
To install required packages and their dependencies, you need to carry out following code:
# update installed packages
update.packages(ask = FALSE)
# List of required CRAN-packages
<- c(
pkgs "ade4",
"devtools",
"ggplot2",
"GGally",
"readODS",
"tidyr",
"vegan",
"viridis")
# Installed Packages only if not yet done
<- rownames(installed.packages())
inst_pkgs install.packages(pkgs = pkgs[!pkgs %in% inst_pkgs])
# Packages from github
library(devtools)
install_github("ropensci/taxlist")
install_github("kamapu/vegtable")
Snippet for Last Session
Copy and paste this script to start the last session.
# Load packages
library(vegan)
library(vegtable)
# Load data
<- readRDS("lalashan.rds")
lalashan
# Calculate frequencies
<- aggregate(plot_id ~ taxon_code,
spp_freq FUN = function(x) length(unique(x)),
data = lalashan$obs)
<- spp_freq[order(spp_freq$plot_id, decreasing = TRUE), ]
spp_freq head(spp_freq)
summary(as.factor(spp_freq$plot_id))
<- with(spp_freq, taxon_code[plot_id > 1])
sel_spp
# Transform abundance values
hist(lalashan$obs$abund)
hist(log(lalashan$obs$abund + 1))
$obs$abund_log <- log(lalashan$obs$abund + 1)
lalashan
# Delete rare species and do cross table
<- crosstable(abund_log ~ taxon_code + plot_id,
cross_table FUN = mean,
data = subset(lalashan$obs, taxon_code %in% sel_spp),
na_to_zero = TRUE,
as_matrix = TRUE)