[R-sig-eco] point color in NMDS (vegan)

Vít Syrovátka syrovat at sci.muni.cz
Mon Aug 19 11:26:33 CEST 2013


Hi Elaine,

Maybe an easier way is to create a factor that will assign the islands 
into groups.
If you want to classify the islands manually, then it might be better 
to use Excel or another tabular processor.
Following your example:

groups<- factor(c('site2', 'site1', 'site1', 'site1', 'site2', 'site2', 
'site3', 'site3', 'site3'))
(supposing the islands are in alphabetical order)

And now one can use the factor as a subscript to pick the right colors:
points(island.NMDS, display = 'species', pch = '+', cex = 0.6, col= 
c('blue','green','red')[groups])

Note that this is a rather basic procedure, which you can learn from 
many documents related to R and easily accessible on the internet, e.g. 
see http://cran.r-project.org/other-docs.html

Cheers,
Vit


Dne 2013-08-19 03:59, Baldwin, Jim -FS napsal:
> 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-bounces at r-project.org
> [mailto:r-sig-ecology-bounces at r-project.org] On Behalf Of Elaine Kuo
> Sent: Sunday, August 18, 2013 4:02 PM
> To: <r-sig-ecology at 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 at 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 at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology



More information about the R-sig-ecology mailing list