# Analysis of community ecology data in R

David Zelený

### Others

You are not allowed to perform this action
en:ordiagrams_examples

Section: Ordination analysis

## Ordination diagrams

R is notoriously not good in drawing ordination diagrams with complex information, because these usually need manual adjustment, which is not easy in R. Generally, if you need ordination diagram with interpretation focused on individual species or samples (with appropriate labels), R may not produce satisfying results - you may consider using CANOCO 4.5 with CanoDraw for Windows or CANOCO 51). However, R can still draw nice ordination diagrams, if the focus is on the overall pattern of samples, the grouping of samples into clusters or projecting linear or surface response of environment onto ordination space (even three dimensional); few examples are below.

The following plotting functions are using results of DCA (detrended correspondence analysis) of Vltava data:

veg.data <- read.delim ('https://raw.githubusercontent.com/zdealveindy/anadat-r/master/data/vltava-spe.txt', row.names = 1)

library (vegan)
DCA <- decorana (veg = log1p (veg.data))

### ordiplot (library vegan)

Draws ordination diagrams.

ordiplot (DCA, display = 'sites', type = 'p')

ordiplot (DCA, display = 'species', type = 't')

### orditorp (library vegan)

Adds the labels onto an ordination diagram, so as they can be read (and don't overlap). First, draw empty diagram using function ordiplot and argument type = 'n'. Then add the labels using function orditorp.

ordiplot (DCA, display = 'sp', type = 'n')
orditorp (DCA, display = 'sp')

### ordilabel (library vegan)

Adds the labels which looks like stickers:

ordiplot (DCA, display = 'sp', type = 'n')
ordilabel (DCA, display = 'sp')

Other options: identify.ordiplot (adding the labels onto diagram by clicking the mouse), orditklabel (interactive diagrams in tcltk interface, but still not too elegant).

### orglhull (needs to be defined, requires library geometry)

A custom function I wrote couple of years ago, drawing the convex hulls around the groups of samples in ordination diagrams. You need to install library geometry first, if not yet done:

install.packages ('geometry')

The definition of the function (author D. Zelený, fix for R version 2.15.0 introduced by Paolo Piras) can be found here: orglhull, or you can directly copy this source script:

source ('http://www.davidzeleny.net/anadat-r/doku.php/en:customized_functions:orglhull?do=export_code&codeblock=1')


And here is how to use it:

orglhull (DCA, groups = env.data\$GROUP, col = 'tomato', alpha = 0.5)

1)
But you will need to calculate the whole analysis in CANOCO.
2)
In the specific case of this dataset it is important, since the samples in the table are sorted according to the order they have been collected in the field; I started in the upper part of the valley and went down, making the vegetation plots; at the valley bottom, I have chosen locality of another transect and started to climb up, making the vegetation plots. This means that the plots sometimes start at the upper part of the transect and sometimes at the bottom.
3)
The GIF animations below are done using the movie3d function from rgl package. This functions requires to have ImageMagick installed on the computer. Detail script how these animations were done is here