Closed rsak-384 closed 1 year ago
Hi!
Firstly thanks for complement, glad you're finding microViz useful 😄
Just to check I understand what you are asking about: You would like the order of the taxa in each bar (each sample) to be dependent on the abundance of each taxon in only that sample. The fill colour of taxa should be consistent across samples, so they can share a single colour legend.
Is that right?
If so, that's quite tricky, I think. As within one ggplot, the order in which bars are stacked is consistent, as it depends on the underlying ordering of the grouping variable's values.
If you don't have that many samples, you could probably achieve this by making one plot per bar and sticking them together with patchwork or cowplot. Keep the colours consistent by specifying a fixed palette using tax_palette
Approximately how many samples do you have, and how variable are their compositions? would the top 10 taxa vary wildly between samples, or just their order? My suspicion is that if you have a lot of samples, allowing the bar stacking order to vary by sample might end up looking chaotic.
Interesting question though, thank you 🙂
Hi
I have a related question, I want to plot the all the taxa that have higher relative abundance than 3% in at least one gruop of samples,. How can I do that?
One way could be:
aggregate your phyloseq taxa to the desired level for your plot. With tax_agg (probably you need to run tax_fix first)
make new filtered copies of the phyloseq one per group, using ps_filter(groupvar== 'level1') etc
filter the taxa in each one of those new phyloseq objects, with tax_filter(min_prevalence = 0.03)
get the names of the taxa from each phyloseq with tax_top or taxa_names
get the union() of all these names
set a colour palette vector with tax_palette, using the union of the names
use your first phyloseq (all samples) to make the barplot, using the tax_palette you just created
Hope this helps, wrote it on my phone on the train so some details might not be exactly right
now more info added on this topic to https://david-barnett.github.io/microViz/articles/web-only/compositions.html
Thanks a lot for the answer! the package is very useful
Hi!
First of all, thank you for creating and sharing this great package, it makes plot generation a lot more easy and convenient.
I have a question regarding the comp_barplot function, more specifically the tax_order argument. Is there any way to sort the lets say 10 taxa by their abundance in each sample, by example, the most abundant taxa would be at the bottom, second most abundant taxa above that and so forth, with optionally the "Other" taxa being at the top, regardless of its abundance. Unfortunately i could not achieve this with the suggested sorting methods.
Sorry if i have missed or misunderstood something in the documentation.