Display taxa bar plots by group instead of sample-id

I was wondering how to visualize taxa bar plots that are grouped by a column in my metatable (e.g. intervention_group) instead of sample_id (first column of my metadata table). I was looking through the forum and am having difficulties finding an answer (I’m sure this is a simple request but I am new to qiime :)) . I am able to see taxa-bar-plots successfully for individual samples but I can’t figure out how to see it by intervention_group. I think I have to create another/modified metadata table? Or do I indicate a column in my current metadata table to serve as the sample-id (if so, how?)? Thanks in advance for any help with this.

This is the command line I used to visualize taxa-bar-plots using on qiime2-2020.11
qiime taxa barplot
–i-table all-apple-table.qza
–i-taxonomy taxonomy.qza
–m-metadata-file apple_metadata.tsv
–o-visualization taxa-bar-plots.qzv

1 Like

Hi @kripow,

Welcome to the forum! I’m not part of the official QIIME 2 team, but I thought I’d chime in. If the kind of barplots you are looking for is similar to below

and if you are a Python user, you may want to check out the Dokdo package I wrote, especially the taxa_abundance_bar_plot method:

qzv_file = 'data/moving-pictures-tutorial/taxa-bar-plots.qzv'

fig, [ax1, ax2, ax3, ax4, ax5] = plt.subplots(1, 5, figsize=(16, 7), gridspec_kw={'width_ratios': [2, 2, 2, 2, 1]})

kwargs = dict(level=6, count=8, sort_by_mean2=False)

api.taxa_abundance_bar_plot(qzv_file,
                            ax=ax1,
                            include_samples={'body-site': ['gut']},
                            **kwargs,
                            artist_kwargs=dict(title='gut'))

api.taxa_abundance_bar_plot(qzv_file,
                            ax=ax2,
                            include_samples={'body-site': ['left palm']},
                            **kwargs,
                            artist_kwargs=dict(title='left palm',
                                               hide_ylabel=True,
                                               hide_yticks=True))

api.taxa_abundance_bar_plot(qzv_file,
                            ax=ax3,
                            include_samples={'body-site': ['right palm']},
                            **kwargs,
                            artist_kwargs=dict(title='right palm',
                                               hide_ylabel=True,
                                               hide_yticks=True))

api.taxa_abundance_bar_plot(qzv_file,
                            ax=ax4,
                            include_samples={'body-site': ['tongue']},
                            **kwargs,
                            artist_kwargs=dict(title='tongue',
                                               hide_ylabel=True,
                                               hide_yticks=True))

api.taxa_abundance_bar_plot(qzv_file,
                            ax=ax5,
                            **kwargs,
                            artist_kwargs=dict(legend_only=True,
                                               legend_loc='upper left',
                                               legend_short=True))

plt.tight_layout()
plt.savefig('images/Dokdo-API/taxa_abundance_bar_plot-9-20210109.png')

You can see the entire Dokdo API here: https://github.com/sbslee/dokdo/wiki/Dokdo-API.

Let me know if you have any questions. Good luck!

3 Likes

Hi! There is a way to perform it in Qiime2. First, you need to group your table. You can easily find this plugin among others by its name. Second, you need to create a new small metadata file in which instead of sample id’s in Sample ID column you will have a names of your groups according to which you want to create a barplot and which you used in step 1 to group feature table.
Use grouped table and new metadata to produce desirable barplot

3 Likes

Thanks for your help. I found this https://docs.qiime2.org/2020.11/plugins/available/feature-table/group/ which I think refers to step 1 of your instructions:
I will try this and hopefully it works!

3 Likes

This looks very interesting and useful, as a Artifact api user. Thank you for sharing

1 Like

@timanix so far so good. Does it matter what order the group names are in the metadata table?

Hi @kripow!

Nope! As long as the values for the IDs are identical (and I do mean identical, ‘foo’ is not the same as ‘Foo’, or ’ foo '), then everything will be matched up as expected. Keep us posted!