gavinsimpson / ggvegan

ggplot-based plots for vegan
https://gavinsimpson.github.io/ggvegan/
GNU General Public License v2.0
113 stars 30 forks source link

Labeling Ordination Plots #20

Closed deltoroi closed 2 years ago

deltoroi commented 6 years ago

Hello, I just used ggvegan to plot a NMDS. Two questions:

Is there an argument that will allow the site and species names to be labeled? Is there a way to plot ellipses on this ordination plot?

jammah commented 3 years ago

No answer to this question?

gavinsimpson commented 2 years ago

Apologies @deltoroi & @jammah for not circling back to this... too many packages, too little time.

The geom argument takes "points" or "text", but I suspect you want the points and the labels. In which case that is not offered in these autoplot methods, but it is relatively straightforward to do this yourself using geoms from the ggrepel package:

library("vegan")
library("ggvegan")
library("dplyr")
library("ggrepel")

data(varespec)

# with the development version of vegan
set.seed(23)
sol <- metaMDS(varespec, dist = "hellinger", autotransform = FALSE)
# if using the CRAN version of vegan
# set.seed(23)
# sol <- metaMDS(decostand(varespec, method = "hellinger"), dist = "euclidean")

scrs <- fortify(sol)

ggplot(data = scrs, aes(x = NMDS1, y = NMDS2)) +
  geom_point(aes(colour = Score, shape = Score)) +
  geom_text_repel(mapping = aes(label = Label), max.overlaps = 20, seed = 34) +
  coord_equal()

issue-20-answer-img

You could do this with plain old geom_label or geom_text by setting the nudge_x and nudge_y arguments but ggrepel takes care of overlapping labels which is likely to occur with these kinds of ordinations.

jammah commented 2 years ago

Many thanks @gavinsimpson