adw96 / DivNet

diversity estimation under ecological networks
83 stars 18 forks source link

feature request: Plot Diversity Estimates per Factor #42

Closed kunstner closed 4 years ago

kunstner commented 4 years ago

Hi, I recently started to use DivNet to estimate Shannon for microbiome samples. I'm wondering whether it is possible to plot only the diversity estimate (e.g. Shannon) just for the factors (and not all individuals). Basically, I could restrict the plot myself by selecting just one sample per group and do the plot based on the estimate and error but I think it would by have such an option in the plot.diversityEstimates() command already implemented.

Best regards, Axel

adw96 commented 4 years ago

Hi Axel! Thanks for your question! I would use distinct on the summary object and just pass it to ggplot as follows.

library(devtools)
library(phyloseq)
library(ggplot2)
library(magrittr)
library(breakaway); packageVersion("breakaway") # 4.6.16
library(tidyverse)
library(speedyseq)
library(DivNet); packageVersion("DivNet") # 0.3.3
dv <- lee_phylum %>% 
  divnet(X="type", ncores = 4)
dv$shannon %>% 
  summary %>%
  bind_cols(lee_phylum %>% sample_data %>% as_data_frame) %>% 
  distinct(estimate, error, lower, upper, type) %>% 
  ggplot(aes(x = type, y = estimate, col = type)) +
  geom_point() +
  geom_segment(aes_string(x = "type", 
                          xend = "type", 
                          y = "lower", yend = "upper"))

Let me know if you have any more questions, and thanks for your patience.

Cheers,

Amy

kunstner commented 4 years ago

Hi @adw96, it's working. Many thanks. I did not know about distinct yet :). In the mean time I implemented an approach using ggpubr::ggviolin (and skipping the error bars because they are tiny in my data). Anyhow, I think both types of plots are nice to show. Best, Axel