jbisanz / qiime2R

Import qiime2 artifacts to R
MIT License
156 stars 53 forks source link

genus level average bar plot #32

Closed khemlalnirmalkar closed 3 years ago

khemlalnirmalkar commented 3 years ago

Hi @jbisanz Thanks for your codes, much easier to make bar plots & heatmaps at different taxonomic level, Please can you also suggest, how to make an average of all samples from each group and make a bar plot/heatmap at the genus level from qzv file? Thanks

jbisanz commented 3 years ago

For philosophical reasons, I am not a huge fan of this type of plot as it doesn't capture the inter-sample variation, I think it is preferable to make box plots of normalized abundance (perhaps CLR) of each phylum/family/etc of interest. To do what you want, you would do something like this:

library(tidyverse)
library(qiime2R)
taxonomy<-read_qza("inst/artifacts/2020.2_moving-pictures/taxonomy.qza")$data %>% parse_taxonomy()
asv<-read_qza("inst/artifacts/2020.2_moving-pictures/table.qza")$data
metadata<-read_q2metadata("inst/artifacts/2020.2_moving-pictures/sample-metadata.tsv")

summarize_taxa(asv, taxonomy)$Phylum %>%
  make_percent() %>%
  as.data.frame() %>%
  rownames_to_column("Phylum") %>%
  pivot_longer(!Phylum, names_to="SampleID", values_to="Abundance") %>%
  left_join(metadata) %>%
  group_by(`body-site`, Phylum) %>%
  summarize(mean_Abundance=mean(Abundance)) %>%
  ungroup() %>%
  pivot_wider(names_from = "body-site", values_from=mean_Abundance) %>%
  as.data.frame() %>%
  column_to_rownames("Phylum") %>%
  taxa_barplot(features = .)
khemlalnirmalkar commented 3 years ago

Thanks @jbisanz I agree, we cant see inter-sample variation but it helps a little to see overall changes in each group,