CalculatorsToolsGuides 日本語
BenchFig › Calculators › Microbiome stacked bar chart (relative abundance) maker
Free statistics calculators

Microbiome stacked bar chart (relative abundance) maker

Using the QIIME 2 taxa barplot directly in a paper usually means a legend dozens of lines long, colours that change from figure to figure, and labels stuck as d__Bacteria;p__…. Paste your summarized table here to get a stacked bar chart of the top genera plus “Others”, with fixed colours and a journal column width.

Updated: BenchFig日本語

Your numbers are processed only in this browser. Nothing is sent to a server (it is gone when you close the page).

or drop a .csv, .tsv, .txt or .xlsx file on the box (read only in this browser)

Samples can be in rows (QIIME 2 layout) or in columns (a provider’s Excel layout). The orientation is detected automatically; if it is wrong, press “Swap rows and columns”. Counts or percentages give the same chart (each sample is rescaled by its total).

Level
Paste groups (sample ID | group)

One line per sample: sample ID and group, separated by a tab (two Excel columns) or a comma. Use this when the table has no group column.

Chart
Journal width
Sample order

The example data are made up (a soil example: common soil genera with invented counts; 12 samples from 3 sites).

Table layout

Open the QIIME 2 taxa barplot (taxa-bar-plots.qzv), choose the level (Level 6 = genus) and use “Download CSV”. Drop the resulting level-6.csv on the box, or paste its contents. For a provider’s Excel file, copy the table and paste it. These layouts are recognised automatically.

QIIME 2 layout (rows = samples): the first column is the sample ID, followed by one column per taxon with the lineage string as the header, then any metadata columns (group, date and so on).

indexd__Bacteria;p__Actinobacteriota;…;g__Streptomycesd__Bacteria;…;g__Arthrobacter…site
A011520702…SiteA
A029881104…SiteA

Provider’s Excel layout (rows = taxa): one of the three below, with one column of values per sample to the right.

(a) TaxonomyA01A02…
d__Bacteria;p__…;g__Streptomyces1520988…
(b) KingdomPhylum…GenusA01A02
BacteriaActinobacteriota…Streptomyces1520988
(c) GenusA01A02…
Streptomyces1520988…

How it is calculated

  1. Aggregate to a level: taxa are grouped by their names down to the chosen level (phylum, family or genus), and rows with the same name are summed.
  2. Shorten names: d__Bacteria;…;f__Lachnospiraceae;g__Blautia → Blautia. When there is no genus name (g__, g__uncultured, __ and so on), the lowest named rank is used: “Lachnospiraceae (unclassified genus)”. g__uncultured and an empty g__ in the same family become one “unclassified genus”. When the same genus name appears in two families, the family is added to tell them apart. In a names-only table, rows such as uncultured or NA become one taxon, “No name (uncultured etc.)”, ranked like any other. Genus names are italic in the chart and the legend.
  3. Relative abundance (%): within each sample, each taxon’s value is divided by the sample total and multiplied by 100.
  4. Top N + Others: the N taxa (default 10) with the highest mean relative abundance across all samples are shown, and the rest are summed as “Others”. With groups, the ranking still uses the mean of all samples, so every group shows the same taxa.
  5. Unassigned kept apart: sequences not assigned to any taxon (Unassigned) are not counted in N, are not mixed into Others, and are shown in dark grey.
  6. Group means: the per-sample percentages are averaged within each group (the same idea as phyloseq’s transform_sample_counts to proportions followed by a group mean; checked to give the same values as R, with phyloseq for the proportions and dplyr for the group means).
  7. Order and colours: within a bar, the top taxon is at the bottom, then the others in rank order, then Unassigned, with Others on top. In the per-sample chart, samples are grouped and, within a group, sorted by the top taxon (or kept in input order). Colours come from a 20-colour set based on the colour-blind-friendly Okabe–Ito palette, assigned in rank order; Others is light grey and Unassigned dark grey. A taxon has the same colour in the group-mean and the per-sample chart. Change any colour with “Change legend colours”.

In the example (genus, top 10), the most abundant genus is Rubrobacter (mean 11.3% across samples), Others average 32.5% and Unassigned 2.3%.

Legend and journal width

Choose 1 column (85 mm) or 2 columns (180 mm) and the page decides whether the legend goes to the right or wraps below the chart. Text is 7 pt. The legend follows the stacking order (Others, Unassigned, …, top taxon from the top down) and has at most N + 2 entries, so the taxa-barplot problem of a legend too long to fit in Word does not arise. Save a PNG at 2× screen size for free.

Key points
  • A top N of about 8–12 is easiest to read (colours stay distinguishable)
  • Use “Group mean” to compare groups; use “Both” to also show sample-to-sample variation
  • Quote numbers from the % table, not from the chart (the table pastes straight into Excel)
  • In the methods, state how % was computed, how means were taken and how the top N was chosen (copy the sentence below)

How it was checked

Per-sample %, group means, the set and order of the top N, Others and Unassigned, name shortening (unclassified genera, duplicate names), swapping rows and columns, identical results from count and % tables, and the handling of zero-total samples, blank and NA cells and thousands separators were all checked against an independent Python (pandas) implementation (13 cases; differences below 10−9 percentage points, except that comparing a % table rounded to 6 decimals with the count table allows up to 10−4 points for rounding). Because the Python code follows the same naming rules as this page, 7 further cases (QIIME 2 level-1 and level-2 headers, total columns, rows without names and so on) were checked against hand-calculated values. The results were also checked against values computed from the same tables in R 4.6.2 with phyloseq 1.56.0 (tax_glom, transform_sample_counts) and dplyr (7 cases: the example table at phylum, family and genus level; a QIIME 2-format phylum table with an Unassigned column, a Total column, a zero-total sample and groups of 2, 3 and 5; QIIME 2-format genus and family tables with uncultured and empty genera, a zero-total sample and groups of 1, 3 and 4; differences below 10−13 percentage points; apart from the example, the tables hold made-up values generated in R). The R code uses the same naming rule (uncultured and similar names mean “unknown at that rank”).

This page does not cover diversity (alpha or beta), PERMANOVA, tests for differentially abundant taxa (LEfSe, ANCOM, DESeq2 and so on) or rarefaction.

References

FAQ

Why is the group mean the mean of per-sample percentages?

Sequencing depth differs between samples. If you sum counts within a group and then convert to %, the deepest samples dominate. Converting each sample to % first and then averaging gives every sample the same weight. In the example, Rubrobacter in SiteA is 5.9% as a mean of per-sample %, but 6.3% when counts are pooled first.

Can I use a table that was not rarefied?

Yes. Relative abundance divides each sample by its own total, which already removes differences in depth, so a stacked bar chart of relative abundance does not need rarefaction. Samples with very few reads (a few hundred) have noisy proportions, though, so decide whether to include them according to your analysis plan.

What is the difference between Others and Unassigned?

Others collects taxa that were classified but are not in the top N. Unassigned is sequences that could not be assigned to any taxon. They mean different things, so this page shows them in different greys and does not count Unassigned in the top N. Taxa such as “Lachnospiraceae (unclassified genus)”, classified to family but not genus, are ranked like any other taxon.

The colours differ from the QIIME 2 taxa barplot

The QIIME 2 taxa barplot assigns colours to the taxa in the table by its own rules. This page assigns a fixed colour-blind-friendly set to the top N only, in rank order (Others and Unassigned are grey). The colours therefore do not match QIIME 2, but the same table and settings always give the same colours, and a taxon has the same colour in the group-mean and the per-sample chart. You can change colours from the legend.

Is my data sent anywhere?

No. Reading the table, the calculation and the chart all happen in your browser; nothing is sent to a server. Dropped files are read only inside the browser. Everything is gone when you close the page.

Other calculators

Related guides

Product names are trademarks or registered trademarks of their respective owners.