## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
library(ecan)

## ----data---------------------------------------------------------------------
data(dune, package = "vegan")
tw <- twinspan(dune)
tw

## ----pseudospecies------------------------------------------------------------
psp <- pseudospecies(dune)
dim(psp)
head(colnames(psp))

## ----ra-----------------------------------------------------------------------
ra <- tw_ra(psp)
ra$eig

## ----preference---------------------------------------------------------------
pos <- ra$sample > 0
pref <- tw_preference(psp, pos)
head(sort(pref))

## ----classification-----------------------------------------------------------
head(tw$classification)
table(tw$classification$group)

## ----dendrogram, fig.width = 7, fig.height = 4--------------------------------
cls <- stats::as.hclust(tw)
plot(cls, hang = -1, main = "TWINSPAN", xlab = "", sub = "")

## ----modified-----------------------------------------------------------------
tw_inertia(psp)
tw_mod <- twinspan(dune, modified = TRUE, n_clusters = 4)
table(tw_mod$classification$group)

## ----two_way------------------------------------------------------------------
tw_two_way(tw)

