Skip to content

on NMDS graphics

2 messages · Sinu P, Gavin Simpson

#
On Wed, 2010-12-08 at 13:54 +0530, Sinu P wrote:
The commonly used procedure is to set up a vector of colours or symbols
you want to use, one per group. Then set up a variable that contains the
group identifier, as a factor. We then index the colours or symbols
vector with our grouping factor to produce the correct length and
specification of parameters col or pch for the plot.

Here is an example:

require(vegan)
data(varespec)

## Ordination
ord <- metaMDS(varespec)

## Dummy forest types, indicator
## stored as a factor
ftypes <- gl(3, nrow(varespec)/3)
## or via something like
ftypes <- factor(rep(paste("Type", 1:3), each = 8))

## plot the data
plot(ord, display = "sites", type = "n")

## add the points coloured by ftype
## 1) specify colours wanted for groups
vcols <- c("red","green","blue")
## or 1) specify symbols for groups
vpch <- c(16,17,18)
## 2) add points using ftypes to index vcols
points(ord, col = vcols[ftypes], pch = vpch[ftypes])

To see what is being done, try:
[1] "red"   "red"   "red"   "red"   "red"   "red"   "red"   "red"   "green"
[10] "green" "green" "green" "green" "green" "green" "green" "blue"  "blue" 
[19] "blue"  "blue"  "blue"  "blue"  "blue"  "blue"

HTH

G