[R-sig-eco] NMDS vegan
Gavin Simpson
gavin.simpson at ucl.ac.uk
Wed Oct 27 08:30:55 CEST 2010
On Tue, 2010-10-26 at 23:03 -0400, Soumi Ray wrote:
> Hi all,
>
> Finally I could get a NMDS plot! My first venture in R! I used ordiplot in
> vegan to make the graph - I have three categories of sites (A-site#1-4,
> B-site#5-15, C=site#16-22) - is it possible to represent these three
> cateories with different symbols. I followed the vegan package code :
>
> fig <-ordiplot (nmds.mds, type="none")
> point (fig, "sites", pch=21, col="red", bg="yellow")
^^^^^^
I presume points() here.
Yes. You need a factor variable holding the site info, to act as an
indicator variable selecting from a choice of plotting characters. The
latter are provided as argument pch.
## Indicator variable - a factor
my.site <- factor(rep(c("A","B","C"), times = c(4,11,7)))
## add points - here we use pch = c(21,22,23)
## and index pch by my.site
points(fig, "sites", pch=(21:23)[my.site], col="red", bg="yellow")
It is instructive to visualise what is going on here. Internally,
my.site can be thought of as a vector of 1s, 2s, and 3s. A 1 refers to
"A", a 2 to "B" and so on. (21:23) is also a vector, of length 3, if we
ask for element 1 from this vector we get 21, element 2 we get 22 etc.
So when we do:
(21:23)[my.site]
what we get is a vector that is the same length as my.site containing
the values, 21, 22, and 23 only. In this way, we specify a 'pch' for
every site, and which pch is chosen depends on which groups of sites a
sample belongs to.
> head((21:23)[my.site])
[1] 21 21 21 21 22 22
> length((21:23)[my.site])
[1] 22
> length(my.site)
[1] 22
HTH
G
> Thanks
>
> Soumi
>
>
>
>
>
> On Mon, Oct 25, 2010 at 2:10 PM, Soumi Ray <soumiray74 at gmail.com> wrote:
>
> > Hi listers,
> >
> > I am trying to run NMDS in vegan package. I have a species dataset - with
> > columns as species and rows as variables. All my data are 0/1
> > (presence/absence). My data has missing values. I saved my data in txt file
> > and the missing values are blank spaces. I am using the syntax:
> > <nmds <-read.table ('nmds.txt', header=T, rows.names=1, sep="\t")
> > <nmds.mds.alt <- metaMDS (nmds, distance="bray", k=2, autotransform=FALSE)
> >
> > But it is showing me the error:
> > Error in distfun(comm, method = distance, ...) :
> > NA/NaN/Inf in foreign function call (arg 1)
> > In addition: Warning message:
> > In distfun(comm, method = distance, ...) :
> > you have empty rows: their dissimilarities may be meaningless in method
> > bray
> >
> > Could anyone kindly let me know where am I going wrong? I admit i am new to
> > R, trying to self tutor myself.
> >
> > Thank you,
> >
> > Regards,
> >
> > Soumi
> >
>
> [[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
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
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-sig-ecology
mailing list