fawda123 / ggord

a take on ordination plots using ggplot2
https://fawda123.github.io/ggord/
62 stars 20 forks source link

Add species name in ggord() db-RDA plotting #22

Closed magibc closed 2 years ago

magibc commented 2 years ago

Hi @fawda123,

It's my first time to try to analyze microbiome data with db-RDA ordination strategy.

Through the webpage: https://fukamilab.github.io/BIO202/06-B-constrained-ordination.html I used your package with my own data and the output likes to me. db-RDAtrial

Nevertheless I would like to know if it is possible to indicate the species name and if exists some restriction as occurs if I follow plot() function with only permits the plot of the name of 80 species and no more. I have 220 species but I would like to plot the species labels that are from >0.25 in axis values.

Thanks on advance for your help,

David.

magibc commented 2 years ago

Solved how to plot species labels but not for a specific axis range... thank you if someone could help or give me some hints.

fawda123 commented 2 years ago

Hi @magibc, if I'm understanding correctly, there is no way to do this within the ggord plot function. However, you could use this code for dbRDA model objects. The species +/- 0.05 are subset prior to plotting.


library(ggord)
library(vegan)
library(ggplot2)
data(varespec)
data(varechem)

ord <- capscale(varespec ~ N + P + K + Condition(Al), varechem, dist = "bray")

# get species
species <- - data.frame(ord$CCA$v[, c('CAP1', 'CAP2')])

# subset by limit
lim <- 0.05
species <- species[species$CAP1 > lim | species$CAP1 < -1 * lim, ]
species <- species[species$CAP2 > lim | species$CAP2 < -1 * lim, ]
species$species <- row.names(species)

# create ggord and add text
ggord(ord, addsize = -1, exp = c(0.05, 0.05)) + 
  geom_text(data = species, aes(x = CAP1, y = CAP2, label = species), col = 'blue')

image