Ordination in R for community data

Ordination in R for ecologists: NMDS, PCA, RDA, CCA and distance-based methods, the tests that go with them, and the model-based alternative to a distance matrix.

A site-by-species table is too wide to look at. Fifty sites and two hundred species is ten thousand numbers, most of them zero, and no amount of staring turns that into a result. Ordination compresses it into a map: sites that support similar assemblages sit close together, and the axes of the map are the directions along which composition actually changes.

The compression is where the work is. An ordination is not a picture of your data, it is a picture of your data after a specific set of decisions, and the decisions are made early, quietly, and usually by default.

This page collects every ordination and multivariate tutorial on this site, in an order that follows the workflow rather than the history of the methods.

The choice you make before you start

The first decision is the dissimilarity index, and it is made before any ordination code runs. Euclidean distance treats two sites sharing no species as more similar when both lack the same absentees, which is the double-zero problem, and it is the reason raw Euclidean distance on community counts is almost always wrong. Bray-Curtis, Jaccard and Hellinger each answer a different question about what “different” means. Change the index and the map changes; nothing downstream can undo it.

Unconstrained, then constrained

An unconstrained ordination asks what the main gradients in composition are, without reference to anything you measured. NMDS is the standard choice for community data because it only uses the rank order of the dissimilarities, PCA is for the environmental table rather than the species table, and hierarchical clustering answers the same question with groups instead of axes.

A constrained ordination asks a different question: how much of the compositional variation can the variables you measured explain, and is that more than chance. The gradient length in the data decides whether a linear or a unimodal method is appropriate, distance-based RDA carries the dissimilarity choice into the constrained world, and variation partitioning splits the explained part between overlapping predictor sets instead of double-counting the shared fraction.

Testing, and the trap in the test

PERMANOVA tests whether groups differ, and it is the natural companion to an NMDS. It also has a well-known failure that is still in print constantly: a significant result can mean the groups differ in location, or it can mean they differ in spread, and the test does not say which. Checking dispersion first is not an optional extra, it is what makes the p-value readable. After that, a significant omnibus test still says nothing about which pairs differ, or which species drive the difference.

The model-based alternative

Distance-based methods have one structural weakness: the mean-variance relationship of count data leaks into the distances. Abundant species vary more in absolute terms, so they dominate the dissimilarity whether or not they carry the ecological signal, and an ordination axis can end up tracking sampling intensity rather than composition. Modelling each species with its own GLM and testing the community by resampling takes that apart. It is not a drop-in replacement, it changes what the test assumes, but on count data where the variance climbs with the mean it answers the question you meant to ask.

The tutorials

The choice underneath everything

Unconstrained ordination

Constrained ordination

Testing what the ordination shows

Which species, and are they associated

Distance matrices on their own

  • Mantel tests - correlating two distance matrices, what that really tests, and when geography looks important and is not.

The model-based alternative

Traits inside the ordination

Where this connects

Newsletter

Get new tutorials by email

New R and QGIS tutorials for ecologists, straight to your inbox. No spam; unsubscribe anytime.

By subscribing you agree to receive these emails and confirm your address once. See the privacy policy.