I am conducting an ordination analysis in R and I'm having trouble dealing with the results of the function metaMDS, from vegan. More specifically, I'm not able to get species scores from the metaMDS result. I found a similar question here How to get 'species score' for ordination with metaMDS()?, but the answer for it did not work for me.
My data is available here: https://drive.google.com/file/d/1btKzAWL_fmJ80GjcgMnwX5m_ls8h8vpY/view?usp=sharing
Here is the code I wrote so far:
library(vegan)
mydata <- read.table("nmdsdata.txt", h=T, row.names=1)
dist.f <- vegdist(mydata, method = "bray")
dist.f2 <- stepacross(dist.f, path = "extended")
results<-metaMDS(dist.f2, trymax=500)
I was told to use the function stepacross since the species composition of my sites is quite different and I was not getting converging results in metaMDS without using it. So far so good.
My problem arises when I try to plot the results:
plot(results, type="t")
When I run that line I receive the following message on my console: "species scores not available". I tried to follow the approach recommended on the link I cited earlier, by running the code:
NMDS<-metaMDS(dist.f2,k=2,trymax=500, distance = "bray")
envfit(NMDS, dist.f2)
However, it does not seem to work here. It returns me the sites scores and not the species scores as it does when using the data from the post I commented earlier. The only difference in my code is that I use "bray" and not "euclidean" distance. In addition, I get a warning after running envfit: "Warning message: In complete.cases(X) & complete.cases(env): longer object length is not a multiple of shorter object length".
I need both sites scores and species scores to plot the results. Am I missing something here? I'm new to R, so consider that, please,
Any help would be appreciated. Thanks in advance.
If you want to have species scores, you must supply information on species. Dissimilarities do not have any information on species, and therefore they won't work. You have two obvious (and documented) alternatives:
metaMDS
and it will calculate the dissimilarities, and if requested, also perform the stepacross
:## bray dissimilarities is the default, noshare triggers stepacross
NMDS <- metaMDS(mydata, noshare = TRUE, autotransform = FALSE, trymax = 500)
This also turns off automatic data transformation as you did not use it in your dissimilarities either.
NMDS <- metaMDS(dist.f2, trymax = 500)
sppscores(NMDS) <- mydata
If you transformed community data, you should use similar transformation for mydata
in sppscores
.