Skip to main content
This page covers how the stacked bar chart works in Cosmos-Hub 2.0: how to read each part of the figure and which parameter shapes it. For what a stacked bar chart is and when to use one, see the Stacked bar chart overview. Because the chart is highly customizable, the output and its controls are described together below.

Module output and customization

  • Annotated Stacked Bar Chart: a stacked bar chart to inspect and compare microbial composition across your cohort, one bar per sample or per group. Sample metadata can be highlighted above the bars, and samples can be sorted, faceted, or collapsed by your variables of interest.
Stacked Barchart 1

Stacked bar chart of phylum-level relative abundances across skin samples, faceted by body site and sorted by dermotype within each facet. Each bar represents one sample, with segments colored by phylum. Low-abundance phyla are grouped under "Others." Color-coded annotation strips above each facet indicate the body site and dermotype of each sample.

Annotated Stacked Bar Chart

1. Set the bar values and scale

All figures on this page show relative abundance (each bar scaled to the same height). You can display composition expressed as counts by setting Y-axis values to absolute and Analysis Metric to counts
The sample bar is the basic unit of stacked bar charts: one bar per sample, divided into stacked colored segments, where each segment’s size is that feature’s abundance in the sample (a feature being a single taxon or function). A single bar is a snapshot of the sample’s whole composition. The scale of y-axis depends on the selected metric used to express feature abundance. Set the scale with Y-axis values:
  • relative shows the proportion of every feature within the sample. Sample bars reach the same height. Best for comparing composition across samples.
  • absolute shows feature counts, so bar heights may also reflect differences in sequencing depth or total counts between samples.

2. Choose how features to show per each Bar

The colored segments are the microbial features (taxa or functions). A single sample profile can include hundreds of features (thousands or more for functional profiles), which can make it hard to visualize all of them within the same Bar. To facilitate comparison between samples, it is suggested to limit the number of features shown per bar by visualizing the most abundant, prevalent or variable features across the cohort, and group remaining features into an aggregate category (Others).
  • Use the Top features (N) parameter to set how many features are displayed individually, and Feature ranking method to decide the ranking criteria to sort microbial features to be selected:
How percentile ranking works. Each feature is ranked by the 90th percentile of its abundance across samples. This favors features that reach a high abundance in at least part of the cohort, making it a balanced middle ground between mean, which favors features that are abundant on average, and prevalence, which favors features detected in many samples.
Where the aggregated category sits in the stack and legend is set by Place “Others” / “Unassigned”, usually last, since these represent less informative features.

3. Annotate samples with metadata

The colored strips above the bars display sample metadata chosen.
  • Choose which metadata to display through Sample annotation parameter: categorical variables (sex, treatment, disease status, cohort) appear as distinct colors, and numerical variables (age, BMI) as a continuous scale.
  • Remove from the plot samples lacking chosen annotation by checking Drop samples with missing annotation.
Why annotations matter. Compositional patterns become meaningful once they can be linked to sample characteristics. With metadata aligned across many samples, a shift that consistently follows a variable like treatment or disease status stands out, suggesting how the variable may shape the community.

4. Set the feature colors

The colors of the feature segments are set by the Feature color palette. Since communities are compared visually by color, a clear, distinguishable palette is what lets real compositional differences stand out rather than blur together among similar shades. This affects appearance only, not the data.

5. Arrange and group the samples

How the bars are organized is controlled by Sample arrangement, with three options: Each option unlocks one or two follow-up parameters: Sort uses Sample ordering metadata to set the order, with Samples in ascending order for the direction. This places samples that share a value (same treatment, cohort, or disease status) next to each other. The ordering options come from whatever you selected in Sample annotation.
Stacked Barchart Sort

Stacked Bar Chart obtained by setting Sample Arrangement to 'sort', and using 'bodysite ' and 'dermotype' as Sample ordering metadata

  • Facet also uses Sample ordering metadata to order samples within each panel, and adds Metadata columns for faceting to choose the variable that splits the panels.
    Stacked Barchart 2

    Stacked Bar Chart faceted by Bodysite and sorted by Dermotype

  • Collapse also uses Sample ordering metadata to define the groups, and shows one bar per group. Each feature segment is the collapsed (summed) composition of the samples in that group, displayed as relative abundance. This is useful for spotting features that shift on group average, but it hides sample-to-sample variability, so it is best when group-level patterns matter more than individual samples.
Stacked Barchart Collapsed

Stacked barchart obtained by setting Sample Arrangement to 'collapse' and 'ethnicity' as Sample Ordering Metadata

Which parameters appear depends on the arrangement. Sort, Facet, and Collapse all reveal Sample ordering metadata (and its direction). Facet additionally reveals Metadata columns for faceting. In every case, the metadata available for ordering is whatever you chose in Sample annotation.

6. Show or hide sample labels

Show sample labels toggles the sample names along the x-axis. Keep them on for small cohorts where identifying individual samples helps, and off for large cohorts where labels would crowd the plot.
Stacked bar charts are descriptive and exploratory. A visible difference in composition should be confirmed with appropriate statistical analysis (differential abundance testing, diversity analysis, or machine-learning models) depending on the question.

Pre-processing

Select your workflow. These pre-processing values vary by data type; the display settings below are the same regardless of workflow.

Stacked Bar Chart settings

Parameter reference

One or more metadata columns shown as colored strips above the bars, connecting composition patterns to sample metadata.Options · Columns from the metadata table associated with the query used to create the analysisDefault · NoneSuggested · Variables relevant to the biological question, such as treatment, disease status, body site, cohort, time point, age group, sex, or sequencing batch. Avoid selecting too many, or the plot becomes hard to read.
Whether samples with missing values in the selected annotation are removed from the plot.Options · TRUE (drop them) or FALSE (keep them)Default · TRUESuggested · Leave TRUE when the annotation is essential and unannotated samples should not appear. Use FALSE to preserve sample size and see where unannotated samples fall.
When TRUE, samples missing the chosen annotation are removed from the plot. When FALSE, they are kept and assigned to a default missing-value group.
How features are ranked before the top N are chosen for display.Options · mean, prevalence, variance, percentileDefault · meanSuggested · percentile is balanced, surfacing features that reach high abundance in a meaningful fraction of samples. Use mean for dominant features, prevalence for widely shared ones, and variance for features that change strongly across samples.
The ranking method controls which features get their own colors. percentile ranks each feature by the 90th percentile of its abundance across samples (zeros included), so sparse features that spike in only a few samples still rank low. Different methods surface different biological patterns.
The number of top-ranked features shown with individual colors.Options · Integer from 1 to 30 Default · 10Suggested · 5–20 depending on dataset complexity and readability; 10 is a practical default.
Features are first ranked by the chosen method, then the top N are displayed individually; the rest are grouped into Others / Unassigned. For example, mean ranking with N = 10 shows the 10 features with the highest average abundance.
Whether the y-axis shows absolute read counts or relative abundance.Options · absolute, relativeDefault · absoluteSuggested · relative for most cross-sample comparisons, since it makes bars directly comparable. absolute when read-count differences are biologically or technically relevant.
Relative abundance is usually easier to interpret; absolute counts vary with sequencing depth, so compare them carefully.
The palette used to color feature segments.Options · Discrete palettes configured in the platformDefault · tab20bSuggested · A palette that makes features easy to tell apart. Discrete palettes are recommended, since each color represents a different taxon or function.
Whether sample names are displayed along the x-axis.Options · TRUE or FALSEDefault · TRUESuggested · TRUE for small cohorts where identifying samples helps; FALSE for many samples where labels crowd the plot.
How samples are organized in the chart.Options · None, sort, facet, collapseDefault · None (samples are ordered alphabetically by sample name)Suggested ·
  • None, no metadata ordering; samples are ordered alphabetically by sample name.
  • sort, order samples by metadata so similar samples sit together.
  • facet, split into panels by a categorical variable to compare groups while keeping individual bars.
  • collapse, summarize into group-level bars for a compact overview.
Arrangement changes only how the chart is organized, not the underlying values. It also determines which follow-up parameters appear: sort, facet, and collapse all enable Sample ordering metadata, and facet additionally enables Metadata columns for faceting. Example: to compare taxonomic profiles across cancer subtypes while showing treatment status, facet by subtype and annotate by treatment.
Available when Sample arrangement is set to sort, facet, or collapse.The metadata column(s) used to order samples. The available choices are the variables you selected in Sample annotation.Options · Any metadata chosen in Sample annotationDefault · NoneSuggested · A variable that makes the plot easier to read, such as disease status, treatment, cohort, time point, body site, or read depth. Sorting by read depth, for instance, can reveal whether composition tracks sequencing depth.
Available when at least one column is chosen in Sample ordering metadata.The direction of sorting for the selected ordering metadata.Options · TRUE (ascending) or FALSE (descending)Default · TRUESuggested · Whichever direction makes the plot easiest to interpret. Affects visual order only, not feature values or sample inclusion.
Whether the aggregated Others / Unassigned segment, which combines the abundance of all features outside the top N, appears at the top or the bottom of each sample’s bar.Options · first, lastDefault · lastSuggested · last for most plots, since this segment represents aggregated, less informative features.
Features outside the top N are grouped into Others / Unassigned to keep the chart readable; this controls where that group sits in the bar.
Available when Sample arrangement is set to facet.The categorical column used to create panels when the chart is faceted.Options · Categorical columns chosen in Sample ordering metadataDefault · NoneSuggested · A categorical variable defining the main groups to divide the chart into, such as disease status, treatment, cohort, body site, cancer subtype, or time point.
Used only when arrangement is facet. Example: faceting by cancer subtype creates a panel per subtype, while sample annotations can still show treatment, sex, or cohort.