0

I am attempting to add 95% confidence ellipse to an NMDS plot using the vegan package and function "ordiellipse" and keep getting the same error message. The ordination looks like this:

microcosm_nmds <- ordinate(physeq = physeq_bac1, method = "NMDS", distance = "bray")

plot_ordination(
  physeq = physeq_bac1,
  ordination = microcosm_nmds,
  color = "day",
  shape = "location",
  title = "NMDS of Microcosm bacterial Communities"
) + 
  scale_color_manual(values = c("red", "#ffae19",
                              "#4daf4a", "#1919ff", "darkorchid3", "magenta")
  ) +
  geom_point(aes(color = day), alpha = 0.7, size = 4) +
  geom_point(colour = "grey90", size = 1.5)

The code for the ellipse I am trying to use is:

ordiellipse(microcosm_nmds, groups = "day", display = "sites", kind = "sd", conf = 0.95, col = "black", w = NULL)

When doing this, I keep getting an error that says "Error in cov.wt(X, W) : 'x' must contain finite values only" and I'm not sure why. There are no NAs or missing values in the data, and the ordination works fine. I can only guess it has something to do with sample weights? But I'm not sure. Any help at all would be much appreciated.

Thanks!

Jari Oksanen
  • 3,287
  • 1
  • 11
  • 15
  • It seems that `microcosms_nmds` is a result object from the **phyloseq** package, and the base plot is a **ggplot2** graph also from **phyloseq**. On the other hand, `ordiellipse()` function is from the **vegan** package, but I have no idea if this can be used together with **phyloseq** result objects, and certainly it cannot be used with **ggplot2** graphics. If you use **phyloseq**, you should use **phyloseq** functions consistently. – Jari Oksanen Jun 21 '18 at 05:53
  • About `ordiellipse()` usage: the `groups` argument should be a variable that is visible to the function. It cannot be just a string (`"day"`), but a variable `day`. However, even after this I don't believe that `vegan::ordiellipse()` will work with `phyloseq::plot_ordination()`. This `day` seems to be in some **phyloseq** object, and you must consult **phyloseq** documentation to find out how to access that variable. I cannot give better advice or try, because I don't have **phyloseq** package in this laptop. – Jari Oksanen Jun 21 '18 at 06:02
  • This makes sense that its probably an issue with trying to use two different packages to reach the same conclusion. You wouldn't perhaps know any other way to generate an NMDS with ellipses based on 16S data, would you? – Kt McBride Jun 22 '18 at 00:03
  • The **phyloseq** package calls `vegan::metaMDS()` for NMDS, and provides its own `phyloseq::plot_ordination()` to replace `vegan:::plot.metaMDS`. You can use **vegan** directly, but for that you need to free your data from **phyloseq** structures. I don't know how this can be done, because I don't have **phyloseq** in my laptop. – Jari Oksanen Jun 22 '18 at 04:58
  • Alternatively, you can look at the way of using **ggplot2** graphics to add the ellipses in `phyloseq::plot_ordination()`. There are several posts on this issue, e.g., https://stackoverflow.com/questions/42799838/follow-up-plotting-ordiellipse-function-from-vegan-package-onto-nmds-plot-creat – Jari Oksanen Jun 22 '18 at 05:05

0 Answers0