0

I've produced an ordination plot from a data frame in R. The data frame consists of species (columns) by sites (rows). There is a group of "treated" sites and a group of control sites within the matrix. However, the way I computed the ordination requires no other variables in the matrix (i.e. no explicit identifier saying that a site is "treated or not". The question: can I label the points in the graph by group without constructing a classification variable? or, can I give the treatment rows (e.g. rows 1:7 one type of symbol and the control (e.g. 8:14) another type?

Here's an example:

#guess i don't have the reputation to post images...hmmm...

#looks something like this (first column is the site)  

#     spec1 spec2 spec3...spec14
#  1    0     1     0  ...    2
#  2    1     5     0  ...    0
#  3    0     2     1  ...    0  
#  .  
#  .  
#  .  
#  14  

# vegan package  
library(vegan)  

# example data matrix is 14x14, species names across columns, sites are numbered automatically upon import of txt file into RStudio  

data(example)  

#vegdist creates a distance matrix of sites  

example.dis <- vegdist(example) 

#monoMDS computes ordination of distance matrix  

example.mds <- monoMDS(example.dis) 

#plot it 

here's where i think i can modify the graph, but I'm not sure how to do it

plot(example.mds)  
user1867613
  • 3
  • 1
  • 3
  • 2
    Welcome to SO. Start by providing us with a reproducible example: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Brandon Bertelsen Nov 30 '12 at 22:15

1 Answers1

4

Yes you can use an external variable to specify for example the color of points.

Here is an example:

# some data
require(vegan)
data(dune)
data(dune.env)

# vector holding the colors
cols <- c("red", "blue", "pink", "green")

# NMDS with bray-curtis distance
nmds <- metaMDS(dune, "bray", 2)

# empty plot
plot(nmds, type = "n")

# Add points colored by Environmental Variable Management
points(nmds, col = cols[dune.env$Management], pch = 16)

# add legend
legend("topright", legend=levels(dune.env$Management), col=cols, pch = 16)

enter image description here

EDi
  • 13,160
  • 2
  • 48
  • 57