The object sol
already has all the information needed to create the multidimensional scaling Plot.
library(vegan)
data(dune)
sol <- metaMDS(dune)
In particular, see the information present within sol$species
:
sol$species
#> MDS1 MDS2
#> Achimill -0.82281011 0.04326590
#> Agrostol 0.71096673 -0.28923350
#> Airaprae -0.52824471 1.67985459
#> Alopgeni 0.39097510 -0.58595238
#> Anthodor -0.72024342 0.65912703
#> Bellpere -0.47837443 -0.24447599
#> Bromhord -0.61896319 -0.33477103
#> Chenalbu 0.59187735 -0.92196207
#> Cirsarve -0.15182360 -0.82170787
#> Comapalu 1.28932890 0.60841273
#> Eleopalu 1.24505152 0.16150523
#> Elymrepe -0.42013221 -0.68024533
#> Empenigr -0.08839391 1.69631104
#> Hyporadi -0.41574036 1.44599800
#> Juncarti 0.91146527 -0.08307932
#> Juncbufo 0.26477479 -0.60759446
#> Lolipere -0.51198132 -0.24808035
#> Planlanc -0.70645461 0.32062556
#> Poaprat -0.38843320 -0.25092040
#> Poatriv -0.15905975 -0.47836891
#> Ranuflam 1.14364071 0.09955908
#> Rumeacet -0.52478430 -0.10531078
#> Sagiproc 0.14315709 -0.18744430
#> Salirepe 0.57483100 0.91107541
#> Scorautu -0.13957081 0.25000786
#> Trifprat -0.77153459 0.08563492
#> Trifrepe -0.07526533 0.04517137
#> Vicilath -0.46793723 0.54915464
#> Bracruta 0.15072189 0.18980509
#> Callcusp 1.42117957 0.38378896
#> attr(,"shrinkage")
#> MDS1 MDS2
#> 0.5160467 0.3713241
#> attr(,"centre")
#> MDS1 MDS2
#> -0.02324753 -0.05510302
Note that all information about the coordinates of the points and their respective species is in this object. Now just create an appropriate data frame and from it create the desired chart.
sol1 <- data.frame(sol$species, spp = rownames(sol$species))
library(ggplot2)
ggplot(sol1, aes(x = MDS1, y = MDS2))+
geom_point()+
geom_text(aes(label = spp))
In my case I still need to relate the species to the places where they were collected and show in the graph. Maybe it is better to edit the question or ask a new question with a df similar to mine.
– GEO
Exactly. The closer the data set provided is to reality and the more complete the question, the more likely someone is to answer it usefully. I find it more productive to ask a new question, because an issue like this would greatly alter the original question.
– Marcus Nunes