Home > OS >  Output from vegan metaMDS won't run in 'fortify' function
Output from vegan metaMDS won't run in 'fortify' function

Time:08-10

I am trying to retrieve the coordinates for each species in my NMDS using the fortify function, but receive:

Error: data must be a data frame, or other object coercible by fortify(), not an S3 object with class metaMDS/monoMDS.

I have tried converting the NMDS output to a dataframe but this did not work. My sample data and my code are below:

spp1 <- c("5", "0", "3", "1", "2") 

spp2 <- c("0", "12", "1", "8", "1") 

spp3 <- c("0", "0", "0", "0", "1") 

bank.plot.nmds <- data.frame(spp1, spp2, spp3) 

Each column represents a species and each row represents a single plot. The NMDS won't converge but with this limited dataset but it should still work for the question.

library(vegan)

nmds1 <- metaMDS(bank.plot.nmds, trymax = 200, k = 3)

fortify(nmds1)

I thought fortify would provide a table with each species' coordinates? Perhaps there is a better way to extract these values?

CodePudding user response:

Unfortunately your code does not run. The metaMDS function requires numeric data, but you have provided character data. It fails immediately:

nmds1 <- metaMDS(bank.plot.nmds, trymax = 200, k = 3)
Error in FUN(X[[i]], ...) : 
  only defined on a data frame with all numeric-alike variables

Changing the values to numeric, produces a solution after 200 runs. Once we have a solution. The manual page for metaMDS indicates where the coordinates are located:

nmds1$points
#         MDS1        MDS2          MDS3
# 1 -0.4190389  0.20668670  5.657877e-09
# 2  0.5730490  0.08114154  1.670744e-10
# 3 -0.2999666  0.17959160 -6.664288e-09
# 4  0.3289082  0.01654348  8.393367e-10
# 5 -0.1829517 -0.48396331  7.174553e-24
# attr(,"centre")
# [1] TRUE
# attr(,"pc")
# [1] TRUE
# attr(,"halfchange")
# [1] FALSE
# attr(,"internalscaling")
# [1] 2.180455

CodePudding user response:

Install my {ggvegan} package from GitHub, which provides a fortify() method for these objects.

https://gavinsimpson.github.io/ggvegan/

  • Related