[R] Vegan plotting- color help
Gavin Simpson
gavin.simpson at ucl.ac.uk
Fri Apr 11 10:01:52 CEST 2008
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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
More information about the R-help
mailing list