# [R] Vegan plotting- color help

stephen sefick ssefick at gmail.com
Fri Apr 11 16:43:31 CEST 2008

```that worked just fine.  I missed the fact that the scores could be
extracted-  I am learning how to think like a programmer it is just
taking time.  Thank you very much for your help

this is the code that I settled on:

sol <- metaMDS(x, distance="jaccard")

shrink <- FALSE ## see argument shrink in ?metaMDS

## get species and site scores
spp.sc <- scores(sol, display = "species", shrink = shrink)
site.sc <- scores(sol, display = "sites")

## work out the ranges
ylim <- range(spp.sc[,2], site.sc[,2])
xlim <- range(spp.sc[,1], site.sc[,1])

## set-up the plotting region
plot(site.sc, xlim = xlim, ylim = ylim, type = "n", asp = 1,
xlab = "NMDS1", ylab = "NMDS2")

## add the row
points(site.sc[c(1:22),c(1:2)], col="red")
points(site.sc[c(23:45),c(1:2)], col="blue")
points(site.sc[c(46:63),c(1:2)], col="yellow")
points(site.sc[c(64:85),c(1:2)], col="green")
points(site.sc[c(86:106),c(1:2)], col="violet")
points(site.sc[c(107:127),c(1:2)], col="orange")
points(site.sc[c(128:148),c(1:2)], col="purple")
points(site.sc[c(148:171),c(1:2)], col="darkred")
points(site.sc[c(172:194),c(1:2)], col="darkblue")
points(site.sc[c(195:217),c(1:2)], col="black")
points(site.sc[c(218:233),c(1:2)], col="bisque")
points(site.sc[c(234:256),c(1:2)], col="cyan")
points(site.sc[c(257:262),c(1:2)], col="azure")
points(site.sc[c(263:267),c(1:2)], col="chartreuse")
points(site.sc[c(268:271),c(1:2)], col="khaki")
points(site.sc[c(272:276),c(1:2)], col="brown")
points(site.sc[c(277:279),c(1:2)], col="aquamarine")
points(site.sc[c(279:286),c(1:2)], col="chocolate")
points(site.sc[c(287:294),c(1:2)], col="cornflowerblue")
points(site.sc[295,c(1:2)], col="coral")
points(site.sc[c(296:299),c(1:2)], col="darkgoldenrod")
points(site.sc[c(300:301),c(1:2)], col="darkgreen")
points(site.sc[302,c(1:2)], col="darkolivegreen")
points(site.sc[c(303:307),c(1:2)], col="burlywood")
text(spp.sc, labels = colnames(x), cex = 0.8)

On Fri, Apr 11, 2008 at 4:01 AM, Gavin Simpson <gavin.simpson at ucl.ac.uk> wrote:
> On Thu, 2008-04-10 at 23:34 -0400, stephen sefick wrote:
>  > I have looked all over the internet for being able to color sites
>  > differently in a plot of an MDS (metaMDS)-  I would like to color the
>  > different sites in the ordination plot (plot or ordiplot).  I have set
>  > the matrix up so that my site code is 1 .... 296 (first column).   is
>  > there a way to make 1-23 blue, 24-40 red etc.
>  > thanks
>  >
>  > Stephen
>  >
>
>  This requires a bit of manipulation. Using the example from ?metaMDS
>
>  data(dune)
>  require(MASS)
>  sol <- metaMDS(dune)
>
>  shrink <- FALSE ## see argument shrink in ?metaMDS
>
>  ## these are the plotting colours, must be a vector of the same
>  ## length (nrow) as the input data, here 20
>  cols <- rep(c("red","blue","green","black"), each = 5)
>
>  ## get species and site scores
>  spp.sc <- scores(sol, display = "species", shrink = shrink)
>  site.sc <- scores(sol, display = "sites")
>
>  ## work out the ranges
>  ylim <- range(spp.sc[,2], site.sc[,2])
>  xlim <- range(spp.sc[,1], site.sc[,1])
>
>  ## set-up the plotting region
>  plot(site.sc, xlim = xlim, ylim = ylim, type = "n", asp = 1,
>      xlab = "NMDS1", ylab = "NMDS2")
>
>  ## add the row
>  text(site.sc, col = cols, labels = rownames(dune), cex = 0.8)
>  text(spp.sc, labels = colnames(dune), cex = 0.8)
>
>  is one way to do this,
>
>  HTH
>
>  G
>
>  --
>  %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>   Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
>   ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
>   Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
>   Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
>   UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
>  %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>
>

--
Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

```