[R] label plotting on nmds diagram

Gavin Simpson gavin.simpson at ucl.ac.uk
Wed Nov 14 20:08:27 CET 2007


On Wed, 2007-11-14 at 15:19 -0300, Antonio Olinto wrote:
> Hi Gavin, thanks for your message.
> 
> You are right. The function nmds is from library labdsv and not from vegan. My
> mistake.
> 
> Well, that's what I did:
> 
> library(vegan)
> library(labdsv)
> nms.euc <- nmds(dis.euc,4)
> initial  value 13.457832 
> iter   5 value 8.589716
> iter  10 value 7.989993
> iter  15 value 7.734503
> iter  20 value 7.539719
> iter  25 value 7.438721
> final  value 7.397254 
> converged
> 
> plot(nms.euc)
> text(nms.euc$points[,1],nms.euc$points[,2],labels=row.names(nms.euc$points),pos=4,cex=0.7)
> # got overwritten labels
> 
> identify(plot(nms.euc))
> numeric(0)
> 
> It seems that ordiplot is not suitable to nmds but only to cca and rda.

Hi Antonio,

You haven't used ordiplot there or created an object of class "ordiplot"
so the problem is that you expected identify to work with an arbitrary
object. Someone would need to write an identify method that could deal
with whatever plot.nmds returns for what you have above to work.

ordiplot is suitable for lots of ordination types (effectively anything
that scores() can deal with) I was just not familiar with nmds() from
labdsv. Having looked at this, nmds() is an even simpler wrapper round
isoMDS() from MASS.

> 
> But you understood exactly what I want. Your example showed for cca what I want
> for nmds plot.

Only because it is easier to write the cca code without having to wait
for metaMDS to finish the random starts ;-)

Here's what I think you need but using vegan and metaMDS for the random
starts and other NMDS sugar...:

require(vegan)
data(varespec)
nms.euc <- metaMDS(varespec, distance = "euclidean", k = 4)
plt <- plot(nms.euc, display = "sites", type = "p")
identify(plt, what = "sites")

I also forgot to mention that NMDS doesn't have species scores as such,
so your example has nothing to do with species as far as I can see - did
you omit something else?

vegan does allow you to get "species" scores via weighted averages
(see ?scores.metaMDS ), e.g.

plt2 <- plot(nms.euc, display = c("species","sites"), type = "p", shrink
= TRUE)
identify(plt2, what = "species", cex = 0.8, col = "red")
identify(plt2, what = "sites", cex = 0.8, col = "black")

Is this what you are looking for?

If you stick with labdsv:::nmds then take a look at plotid.nmds() which
is a wrapper around identify for nmds objects, which appears to do the
hard work for you. You could look at this to see how you could have gone
about crafting the identify call yourself - the function is very simple.

Alternatively, do look at orditorp() in vegan, as it is a nice function
that allows you to display only labels for species/sites that can fit:

plot(nms.euc, display = c("species","sites"), type = "n", shrink = TRUE)
points(nms.euc, display = "sites", cex = 0.7)
orditorp(nms.euc, display = "species", shrink = TRUE, col = "red")

The orditorp call will generate some warnings - they are harmless and
have been fixed in the latest development version of vegan on R-Forge.
Jari is planning a release of vegan real soon now that will contain this
fix.

Note that orditorp has a priority argument, which you can use to give
labelling priority to species/sites, say based on their maximal
abundance or number of occurrences or similar; see ?orditorp

HTH

G

> 
> Best regards,
> 
> Antonio
> 
> 
> Citando Gavin Simpson <gavin.simpson at ucl.ac.uk>:
> 
> > On Wed, 2007-11-14 at 11:22 -0300, Antonio Olinto wrote:
> > > Hi,
> > > 
> > > I'm using nmds command (library vegan) to analyze some fishing data.
> > 
> > I doubt it - there is no nmds command. Do you mean metaMDS() ? This uses
> > isoMDS() from package MASS with some extra features.
> > 
> > > 
> > > I'd like to plot not only points, but also the names of species and
> > stations in
> > > a specified position.
> > > 
> > > I used the command
> > > text(nmds$points[,1], nmds $points[,2],labels=row.names(nmds
> > > $points),pos=3,cex=0.5)
> > > 
> > > But the labels are sometimes overlapped.
> > > 
> > > Is there any way to use identify, or a similar command, to plot the row
> > names in
> > > a given position? Identify would be perfect but it indicates the row number
> > and
> > > I'd like to have the row name given in nmds$points.
> > 
> > Have a look at ?orditorp in vegan for an alternative approach, but yes
> > you can use identify, but you have to capture the output of the plot
> > call and use that in your identify call:
> > 
> > require(vegan)
> > data(varespec)
> > mod <- cca(varespec)
> > mod.plt <- plot(mod, display = "species", type = "p")
> > identify(mod.plt)
> > 
> > See ?identify.ordiplot for more info.
> > 
> > HTH
> > 
> > > 
> > > Many thanks,
> > > 
> > > Antonio Olinto
> > > Sao Paulo Fisheries Institute
> > > Brasil
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > -------------------------------------------------
> > > BCMG Internet Webmail
> > > www.bcmg.com.br
> > > 
> > > ______________________________________________
> > > 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.
> > -- 
> > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> >  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
> > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> > 
> > 
> 
> 
> 
> 
> -------------------------------------------------
> BCMG Internet Webmail
> www.bcmg.com.br
> 
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 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