Composition barplot sorting by 1 taxon
Closed this issue · 4 comments
First of all I would like to congratulate your R package.
I have been used your package in the past without any issues but now in another phyloseq object I cannot sort by 1 taxon at genus and species level. For phylum, Class, Order and Family no problem to plot it properly (ordered).
Always, for each taxa rank level I perform tax_glom() from phyloseq to the desired taxa before to plot comp_barplot.
I suspected that could be due to the space in the specie name:
S16_ps_specie %>%
tax_fix() %>%
tax_agg("Species") %>%
tax_transform("compositional") %>%
ps_arrange(desc("Mesomycoplasma dispar"), .target = "otu_table") %>%
comp_barplot(tax_level = "Species", sample_order = "asis") +
coord_flip()
But after I changed the phyloseq object for this specie to be Mesomycoplasma_dispar, but the problem persists.
I use tax_fix() because I have the Error in tax_agg(., "Species") : NAs in tax_table at rank: Species
I do not know what could be the problem to fix this. If it is necessary I can send you the phyloseq objects by private.
Thanks on advance,
Magi
Glad you're finding microViz useful, Magi 😄
Can you give an example of your code that is running correctly? E.g ordering by a family
Do I understand correctly that your issue is that you are able to make a bar plot but that the bars are not in the order that you expect? They do not appear to be ordered in descending relative abundance of your target species.
How abundant is the species of interest? Is it possible that many of the samples have zero abundance or otherwise equal abundances?
Cheers
David
Thanks Dr. David Barnett for your rapid feedback.
Yes, I give you an example for family that works:
S16_ps_genus %>%
tax_fix() %>%
tax_agg("Family") %>%
tax_transform("compositional") %>%
ps_arrange(desc(Microbacteriaceae), .target = "otu_table") %>%
comp_barplot(tax_level = "Family", sample_order = "asis") +
coord_flip()
Exactly, my issue is that I am able to make the bar plot but the bars are not plotted in descending order. I can confirm that all the samples (20 samplees) shares the more abundant genus and specie.
Thanks again,
Magí
I think the issue is that the species name should not be a string for the arranging, i.e. something like this below should work. A tiny modification of your original code :)
S16_ps_specie %>%
tax_fix() %>%
tax_agg("Species") %>%
tax_transform("compositional") %>%
ps_arrange(desc(`Mesomycoplasma dispar`), .target = "otu_table") %>%
comp_barplot(tax_level = "Species", sample_order = "asis") +
coord_flip()
Thank you very much David.
The ' symbol insted of " works as desired to sort for 1 taxa!
I close the issue.
Thanks again!!!
Magí