customizing taxonomy barplot

Is it possible to customize the taxa_barplot further? I am splitting my samples into 10 patients and I was hoping to customize the layout of the plot so my faceted figures are in 2 rows of 5 instead of 1 row of 10.

For example, for "cateogry" in taxa_barplot I am using my patient ID's, but can I adjust the placement of the facets instead of having them squashed next to eachother?

Also, for the legend can I have it so only the Genus is displayed rather than the entire taxon string? E.g. Staphylcocccus instead of Bactera;Firmicutes;etc

1 Like

Hi! As far as I know, there is no way to do it in Qiime2, but you can use Python or R to redraw it. Or manipulate the produced image in some editor.

You can download legend as a .svg file and edit it in svg editor (inkspace) or with a script. But if you redraw your figure in R or Python, you can modify it there.

1 Like

I was hoping to do it in R. I generated the image using the taxa_barplot function that is part of the Qiime2R package, I was hoping there was a way to customize the code to alter the layout of the figure regarding how the facets are arragned.

I was also hoping to alter the legend in R as well to collapse the text to genus only. I can redraw the figure I'm just not sure how to manipulate the data in R to do it.

You can manipulate the table that contains taxonomy names to split taxonomy names and leave only Genus level annotations and recreate the plot with modified information. Also you can create your own barplot with subplots (2 rows by 5 columns), custom order and so on. But it is already pure R, not Qiime2.
I used Python to create my barplot like this:

How would I manipulate the table like that in R?

It should be your own script since it is outside of Qiime2.

Hello Michael,

A while ago, I had similar issues but could not find any solutions. So I decided to write myself a lightweight Python package called ‘Dokdo’ (GitHub - sbslee/dokdo: A Python package for microbiome sequencing analysis with QIIME 2). Look at the example below and see if this is what you were looking for.

For this example, I used Dokdo's taxa_abundance_plot method on the taxa-bar-plots.qzv file from the famous "Moving Pictures" tutorial (see the Dokdo API for more details on the method). You should be able to recreate the example using the code shown below.

In addition to plotting taxonomic bar plots, you can also use the Dokdo API for plotting many other types of figures, including PCoA and alpha rarefaction curve plots which cannot be easily customized within QIIME 2 Visualizations.

Let me know if you have any questions.

import sys
sys.path.append('/path/to/dokdo')
import api

import matplotlib.pyplot as plt
%matplotlib inline

fig, [ax1, ax2] = plt.subplots(2, 1, figsize=(19, 12))

api.taxa_abundance_plot('moving-pictures-tutorial/taxa-bar-plots.qzv',
                        exclude_samples={'body-site': ['gut', 'tongue']},
                        level=6,
                        count=8,
                        show_legend=True,
                        legend_loc='upper left',
                        legend_short=True,
                        ax=ax1)

api.taxa_abundance_plot('moving-pictures-tutorial/taxa-bar-plots.qzv',
                        exclude_samples={'body-site': ['left palm', 'right palm']},
                        level=6,
                        count=8,
                        show_legend=True,
                        legend_loc='upper left',
                        legend_short=True,
                        ax=ax2)

plt.tight_layout()
plt.savefig('taxa-bar-plots.png')

2 Likes

Hi Michael,

You should be able to override the facet command inside taxa barplot with something like taxa_barplot(.) + facet_wrap(~PatientID, ncol=5).

Jordan

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.