Re: [R] Vegan plotting- color help

From: Gavin Simpson <gavin.simpson_at_ucl.ac.uk>
Date: Fri, 11 Apr 2008 09:01:52 +0100

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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 11 Apr 2008 - 08:05:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 11 Apr 2008 - 15:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive