I assume that the dataset "island" is yours so I've made that equivalent to an 
example dataset in vegan named "dune".  Below is a rather brute force way to 
assign colors.

library(MASS)
library(vegan)

data(dune)
island = dune
island.NMDS  <-  metaMDS(island,k=2, distfun  =  betadiver,
  distance  = "sim", trymax=100, zerodist="add")

plot(island.NMDS, type = "n")

# species as symbols
col = rep("black",dim(island)[2])
c = colnames(island)
col[c=="Belper" | c=="Elepal" | c=="Viclat" | c=="Brarut"] = "blue"
col[c=="Airpra" | c=="Rumace" | c=="Potpal" | c=="Tripra"] = "red"
col[c=="Sagpro" | c=="Agrsto" | c=="Hyprad" | c=="Poapra"] = "green"
points(island.NMDS, display = 'species', pch = '+', cex = 0.6, col=col)

# sites as text
col = rep("black",dim(island)[1])
r = rownames(island)
col[r=="2" | r=="17" | r=="18"] = "blue"
col[r=="3" | r=="10" | r=="20"] = "red"
text(island.NMDS, display = 'sites',col=col)

Jim Baldwin
USDA Forest Service


-----Original Message-----
From: r-sig-ecology-boun...@r-project.org 
[mailto:r-sig-ecology-boun...@r-project.org] On Behalf Of Elaine Kuo
Sent: Sunday, August 18, 2013 4:02 PM
To: <r-sig-ecology@r-project.org>
Subject: [R-sig-eco] point color in NMDS (vegan)

Dear List,



This is Elaine.

I am using metaMDS in package vegan to plot NMDS.

However, I want to draw the points using different colors according to island 
sites.

For example:

island site 1: island B, C, D => blue

island site 2: island A, E, F => green

island site 3: island G, H, J => red



Please kindly advise how to modify the following code to classify the sites by 
colors.

Thank you



Elaine



library(MASS)

  library(vegan)

  island.NMDS  <-  metaMDS(island,k=2, distfun  =  betadiver,  distance  =
"sim",trymax=100,zerodist="add")

  plot(island.NMDS,  type  =  "n")



  # species as symbols

  points(island.NMDS, display = 'species', pch = '+', cex = 0.6)



  # sites as text

  text(island.NMDS, display = 'sites')

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology





This electronic message contains information generated by the USDA solely for 
the intended recipients. Any unauthorized interception of this message or the 
use or disclosure of the information it contains may violate the law and 
subject the violator to civil or criminal penalties. If you believe you have 
received this message in error, please notify the sender and delete the email 
immediately.

_______________________________________________
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology

Reply via email to