gmteunisse / fantaxtic

Fantaxtic - Nested Bar Plots for Phyloseq Data
26 stars 3 forks source link

Making a stacked bar chart with different taxonomic levels #7

Closed pauGuas closed 2 years ago

pauGuas commented 2 years ago

Hello, When I run the top 20 taxa on my data, my results come back with different taxonomic levels (mostly genus but some are only down to family, etc.). How can I run the bar chart so that all of the top 20 taxa are assigned the lowest taxonomic level possible? When I run the code using just "Genus," I get a lot of "unknown."

top20 <- get_top_taxa(ps_norm, 20, relative = TRUE, discard_other = FALSE, other_label = "Other") top20g <- fantaxtic_bar(top20, color_by = "Genus", label_by = "Genus", facet_by = NULL, grid_by = NULL, other_color = "Grey") -> ptop15

Also...is there a way to combine ASVs of the same genus in the graph? For instance, I would like to combine all the ASVs that are labelled Flavobacteria.

Finally...is there a way to figure out what % of the ASVs are classified as "unknown?"

Thank you!

gmteunisse commented 2 years ago

Hi Pau,

If you want to only display taxa that have annotations at a certain taxonomic level or collapse them, you need to modify your phyloseq object before passing it to Fantaxtic. You can remove all taxa that don't have an annotation at the desired level using basic phyloseq functions, for example prune_taxa. Likewise, you can collapse taxa with the same annotation at a taxonomic level using basic phyloseq functions like tax_glom. Finally, to get the amount of unknown ASVs at any taxonomic you can count the number of NAs in your phyloseq object (e.g. ps_obj %>% tax_table() %>% as.data.frame() %>% summarise(across(everything(), ~sum(is.na(.))))

These questions are all related to phyloseq rather than Fantaxtic, so I'm going to close this issue if you don't mind. I hope I've pointed you in the right direction.