Skip to content
Written for v1.2.0· Last updated: Jul 1, 2026

Bar Plot & Stacked Bar Plot

Core Feature

This feature is available in all Portrai Explorer deployments.

Bar plots summarize a value per group — one bar for each cell type, cluster, or sample. They answer questions like "what is the mean expression of GZMB in each cluster?" or "how many cells are in each sample?". This is the same idea as a grouped bar chart in scanpy.pl.dotplot/sc.pl.matrixplot aggregations, or a barplot built from Seurat::AverageExpression.

The Stacked Bar Plot is a sibling type focused on composition rather than a single summary. Instead of one value per group, each bar is split into colored segments showing how a second categorical variable is distributed within that group — the standard "cell-type composition per sample" chart you see throughout spatial and single-cell papers. Both types live in the same Plot dashboard, are configured from the sidebar, and persist their settings per project.

Creating a Bar Plot

Bar plots are added like any other plot panel in the Plot Dashboard:

  1. Open the Plot dashboard
  2. Add a plot and choose Bar (per-group summary) or Stacked Bar (composition)
  3. The new panel appears in the grid and its options open in the sidebar

Each panel is independent: you can add, rename, duplicate, delete, resize, and drag it. The sidebar lists every plot in the project so you can switch between their settings.


Bar Plot

A Bar Plot aggregates a single variable across the categories of a categorical column and draws one bar per category. It is built for comparing values (mean / median / sum / count), not distributions — for distributions use the Violin Plot or Box Plot.

Configuring the Bar Plot

Group By

The Group By selector chooses the categorical column whose categories become the bars (one bar per category). Only categorical columns are listed — for example cell type, cluster, sample, or condition.

Variable

The Variable selector chooses what is aggregated into each bar's height. It offers two kinds of source, mirroring the Scatter Plot axis selector:

SourceDescription
ColumnA continuous feature (gene expression, a metric, an embedding dim)
SignatureA Signature; its computed score is used as the value

INFO

The Variable selector is hidden when Aggregation is set to Count, because counting rows per group does not need a value column.

Aggregation

Aggregation controls how the per-group values are reduced to one bar height:

AggregationBar height is…
MeanAverage of the variable within the group
MedianMedian of the variable within the group
SumSum of the variable within the group
CountNumber of cells in the group, no Variable needed (default)

Cells with non-finite values are skipped, and empty groups are omitted from the chart.

Error Bars

When Aggregation is Mean, an Error Bars selector appears:

OptionWhisker shows
NoneNo error bars
Std DevSample standard deviation (Bessel-corrected, ÷ n−1)
Std ErrorStandard error of the mean (SD ÷ √n)

Error bars are drawn as a capped whisker centered on the bar's mean. They require at least two cells in a group; single-cell groups show no whisker. Error bars apply only to the Mean aggregation.

TIP

Use Std Dev to describe the spread of values in each group, and Std Error to convey confidence in the group mean — Std Error shrinks as n grows, while Std Dev does not.

Orientation

The Orientation selector switches between Vertical (bars grow up from the baseline, categories along the X axis) and Horizontal (bars grow right, categories along the Y axis). Horizontal orientation is convenient when you have many groups or long category names, since labels read left-to-right.

Sort Bars

Sort Bars controls the order of bars along the category axis:

OptionOrder
Category orderThe column's native category order (default)
Value ↓Largest aggregated value first
Value ↑Smallest aggregated value first

Settings

The following appearance toggles are in the Bar Plot's sidebar settings:

ControlDescription
Show GridToggle the value-axis grid lines (default on)
Show Value LabelsPrint the numeric value above (or beside) each bar (default off)

The bars themselves use a fixed fill opacity (0.85) and occupy 80% of their per-group slot. Bar colors come from the category color scale of the Group By column, so they stay consistent with the same column shown elsewhere — see Color Mapping.

INFO

The bar value axis is always linear with a zero baseline. Non-linear scales (log/sqrt) would break the length-proportionality that makes a bar readable, so there is no scale selector for bars — unlike the Scatter Plot.

Axis Titles

Axis titles are generated automatically. The category axis is titled with the Group By column name. The value axis reflects the aggregation: Count, or Mean of <Variable> / Median of <Variable> / Sum of <Variable>.

Interacting

Hovering anywhere within a bar's column (not just the filled rectangle, so tiny or zero-height bars stay easy to reach) shows a tooltip with:

  • The category label
  • The aggregated value, with ± error appended when error bars are active
  • n = the number of cells contributing to the bar

Export

Each plot panel's titlebar — the top bar of the panel, beside the ⋯ menu and ✕ close button — holds the plot toolbar. To export:

  1. Click the Export (download) button in the panel titlebar
  2. Choose Capture PNG
  3. A PNG is downloaded, capturing the bars, axes, titles, value labels, and error bars exactly as shown

The same popover also offers Capture SVG (vector graphics) and Export data as CSVDownload All Data, or Download Selected Data for the current visibility selection.

See Image Export and Plot Data CSV Export for more on exporting.

Bar Plot Use Cases

Mean expression per cell type

  1. Group By = cell type
  2. Variable = a marker gene
  3. Aggregation = Mean, Error Bars = Std Dev
  4. Sort Value ↓ to rank cell types by expression

Cell counts per sample

  1. Group By = sample
  2. Aggregation = Count
  3. Compare how many cells each sample contributed

Pathway activity by cluster

  1. Create a Signature
  2. Group By = cluster, Variable = the Signature, Aggregation = Mean
  3. Identify clusters with the highest pathway score

Stacked Bar Plot

A Stacked Bar Plot cross-tabulates two categorical columns. Each category of the Group By column becomes a bar, and within each bar the categories of the Stack By column are stacked as colored segments. This is the canonical view for composition / proportion across groups — for example, the proportion of each cell type within every sample or cluster.

Configuring the Stacked Bar Plot

Group By and Stack By

Both selectors accept categorical columns only:

SelectorRole
Group ByThe categorical column whose categories become the bars (X axis)
Stack ByThe categorical column composed within each bar (the colored segments)

A typical pairing is Group By = sample (or cluster) and Stack By = cell type.

Mode

The Mode selector chooses what segment length encodes:

ModeEach bar…
Proportion (100%)Fills the full axis; segments are within-group proportions summing to 100% (default)
CountHas length equal to the group's total count, relative to the largest group

Use Proportion to compare composition regardless of group size, and Count when absolute abundance matters.

Orientation

As with the Bar Plot, Orientation switches between Vertical (segments stack upward) and Horizontal (segments stack rightward).

Sort Bars

Sort Bars orders the bars by their total cell count:

OptionOrder
Category orderThe column's native category order (default)
Group count ↓Largest group total first
Group count ↑Smallest group total first

Stacking order

All stack categories present after filtering are drawn, ordered by overall abundance.

INFO

A shared stacking order is used across every bar: each stack category sits at the same position and keeps the same color in every bar, so segments are directly comparable from bar to bar. The legend lists exactly the drawn segments — all present categories, by abundance.

Settings

ControlDescription
Show GridToggle the value-axis grid lines (default on)
Show LegendShow the Stack By legend in the right margin (default on)

Segment colors come from the category color scale of the Stack By column. The legend is rendered inside the chart's right margin so it is included in PNG exports. Segment fill uses a fixed opacity (0.85).

Axis Titles

The category axis is titled with the Group By column name; the value axis is titled Proportion (in Proportion mode) or Count (in Count mode). The legend header is the Stack By column name.

Interacting

Stacked bars use a shared, whole-column tooltip: hovering anywhere in a bar's column shows a single tooltip for that entire group (rather than one tooltip per segment). It lists:

  • The group label and the group's total cell count (n = …)
  • Every segment with its raw count and its within-group percentage

In addition, a small n=<total> label is drawn at the end of each bar so you can tell a composition built from few cells apart from one built from many — important in Proportion mode, where two very differently sized groups can look identical.

Export

Stacked bar export works the same as the Bar Plot: click Export in the panel titlebar, then Capture PNG (or Capture SVG for vector output, or Export data as CSV). The exported image includes the bars, the legend, axis titles, and per-bar n labels.

Stacked Bar Use Cases

Cell-type composition per sample

  1. Group By = sample
  2. Stack By = cell type
  3. Mode = Proportion (100%)
  4. Compare how cell-type makeup shifts across samples or conditions

Cluster composition by condition

  1. Group By = cluster
  2. Stack By = condition (e.g. treated vs. control)
  3. Mode = Proportion to see condition mix per cluster, or Count for absolute sizes

TIP

Apply a Subset or Lasso Selection and both plot types recompute on only the visible cells — a quick way to inspect the composition of a region or gated population.

Troubleshooting

Plot is empty

  • Bar: confirm a Group By column is selected, and a Variable when the aggregation is not Count.
  • Stacked Bar: both Group By and Stack By must be selected.
  • Verify the data has finished loading; restored plots lazily download their columns.
  • Check that an active Subset is not excluding all cells.

A category is missing

  • Groups with zero cells (after filtering) are omitted by design.
  • In Stacked Bar, stack categories with zero cells (after filtering) are omitted from both the bars and the legend.

Bars look the same size in Stacked Bar

  • In Proportion mode every bar fills the full axis. Switch to Count mode, or read the per-bar n= labels, to compare absolute sizes.

Error bars don't appear

  • Error bars only show for the Mean aggregation and require at least two cells per group.

Portrai Explorer Documentation