0

I am trying to overlay envfit arrows on to an NMDS chart like this one (which is when I replace missing values with fake numbers): Expected NMDS

However, with our actual data, it doesnt give the arrows but labels each point individually, like this: Broken NMDS

Any suggestions would be appreciated.

Code:
# Make MDS
x.mds <- metaMDS(x_matrix, trace = FALSE)
# Extract point co-ordinates for putting into ggplot
NMDS <- data.frame(MDS1 = x.mds$points[,1], MDS2 = x.mds$points[,2])

p <- ggplot(NMDS, aes(MDS1, MDS2))
p + geom_point()

#environmental variables
ef <- envfit(x.mds ~ pH + Ammonia + DO, x.env)
ef <- envfit(x.mds ~ pH + Ammonia + DO, x.env, na.rm = TRUE)    ##ALTERNATIVE
plot(ef)

Data:

Sample  Region  pH  Ammonia Nitrate BOD DO
15  N   7.618   0.042   0.845   1   NA  
34  N   7.911   0.04    7.41    8   5.62    
42  SE  7.75    NA  3.82    1   21.629  
........


> ef

***VECTORS

           NMDS1    NMDS2     r2 Pr(>r)
pH       0.50849 -0.86107 0.0565  0.719
Ammonia  0.99050 -0.13751 0.0998  0.504
DO      -0.88859 -0.45871 0.1640  0.319
P values based on 999 permutations.

1 observation deleted due to missingness

> str(ef)
List of 3
 $ vectors  :List of 4
  ..$ arrows      : num [1:3, 1:2] 0.508 0.991 -0.889 -0.861 -0.138 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:3] "pH" "Ammonia" "DO"
  .. .. ..$ : chr [1:2] "NMDS1" "NMDS2"
  .. ..- attr(*, "decostand")= chr "normalize"
  ..$ r           : Named num [1:3] 0.0565 0.0998 0.164
  .. ..- attr(*, "names")= chr [1:3] "pH" "Ammonia" "DO"
  ..$ permutations: num 999
  ..$ pvals       : num [1:3] 0.719 0.504 0.319
  ..- attr(*, "class")= chr "vectorfit"
 $ factors  : NULL
 $ na.action:Class 'omit'  int 17
 - attr(*, "class")= chr "envfit"
Daniel
  • 289
  • 2
  • 14
  • What does `plot(ef)` give? We have no idea how you produced those **ggplot2** plots as vegan knows nothing about **ggplot2**. If you can show something reproducible I'll take a look. – Gavin Simpson Mar 17 '14 at 19:30
  • I've added the lines into the "Code:" section above, for formatting. Basically, after making the matrix I pulled out the point co-ordinates so that I could use ggplot2 for prettiness! If I run plot(ef) on a new plot it just dumps the values in the corner of a blank workspace. – Daniel Mar 18 '14 at 10:12
  • Looks like pH is a factor (although you think it isn't). What does the result object `ef` say: does it list as a fitted vector or a fitted factor? – Jari Oksanen Mar 18 '14 at 14:13
  • @Mabeuf You *do not* show how you placed the blue `ph` points nor the arrows on the ggplots. This is important as it could be something screwy going on with your ggplotting code. Jari may well be correct about pH being coded wrongly, but as you aren't showing how you created those plots, there's little more to say. Other than, show the output of `ef` and perhaps also `str(x.env)` so we can see how your data are recorded - it is obvious from the way data frames are printed. – Gavin Simpson Mar 18 '14 at 14:47
  • I'm sorry, I don't understand. My exact code is here: http://textdump.net/read/4461/, but it's basically what I have above. EDIT: Ok, so there's a typo in there with an extra envfit '+', but that wasn't there upto 10 seconds before uploading it to that site. – Daniel Mar 18 '14 at 15:14
  • My input data is here: http://textdump.net/read/4462/ and the x.env is here: http://textdump.net/read/4463/ – Daniel Mar 18 '14 at 15:15
  • I've added the ef and str(ef) too. Thank you for the effort and the advice, it's really appreciated. – Daniel Mar 18 '14 at 15:20
  • @Mabeuf This is getting frustrating; you show a ggplot graphic with projected biplot arrows, and a second one with lots of blue pH points. How did you draw those plots!? All you show is code to draw the MDS (site) location points. From what I can see here, `ef` looks fine - it didn't interpret pH as a factor as all the info is in the `***Vectors` section. Also, as **vegan** *does not do any plotting with **ggplot2***, this looks very much like user error in the production of the ggplot figures. But unless you show that code, how can we tell!? – Gavin Simpson Mar 20 '14 at 15:39

0 Answers0