Method · Statistics Library

Bar chart

A bar chart shows the frequency (or percentage) of each level of a categorical variable, with one bar per category and bar height equal to the count.

Topic indexA reference reading outside the guided chapter sequence

Understand the idea

A bar chart answers a simple question: for a column that sorts rows into named groups (blood type, region, product line), how many rows fall into each group? Each distinct category gets its own bar, and the height of that bar is just how many times that category showed up.

It is easy to mix up with a histogram because both use bars, but they answer genuinely different questions. A bar chart's categories have no inherent numeric order or width: 'A', 'B', 'AB', 'O' blood types could be listed in any order. A histogram's bars instead represent equal-width slices of a genuinely NUMERIC range, and the order of the bars along the axis is meaningful. Use a bar chart for categories (nominal or ordinal data); use a histogram for continuous measurements.

Sorting the bars by count (largest first, Pareto-style) is usually the most readable choice when you want to immediately spot the dominant and rare categories, rather than leaving them in whatever order the categories happen to appear in the data.

A bar chart, also called a bar graph, is often used as a frequency chart: one bar per category, with the height showing the category counts.

Practitioner explanation

KernelStats counts non-null values of the selected categorical column via a pure-polars value_counts (no pyarrow dependency) and offers four sort settings: auto (the default: a column of numbers is drawn in its own order, smallest first, and any other column with the largest count first), descending by count (Pareto-style), ascending by count, or alphabetical by category label. The caption reports the total category count and names the single most frequent category with its count, giving an at-a-glance summary alongside the visual.

This is a purely descriptive visualization with no underlying statistical model, no p-value, and no assumption checks: it is a direct tabulation of category frequencies. When category counts warrant a formal comparison (are the categories equally common, or does a categorical variable differ across groups), the appropriate next step is a chi-square goodness-of-fit or independence test, not an inference drawn from the bar heights alone. KernelStats' goodness-of-fit card tests against equal expected frequencies by default (Compare with: uniform), or against expected shares you type in its Expected shares box, such as 9:3:3:1 (Compare with: proportions).

When to use it

Consider it when

You want to see how often each level of a categorical variable occurs, spot dominant or rare categories, or take a first look before a chi-square test.

Use caution when

The variable is continuous/numeric (use a histogram instead, which bins equal-width numeric ranges rather than plotting discrete named categories), or you need a formal statistical test of whether category frequencies differ from equal shares (a bar chart is descriptive only; use the chi-square goodness-of-fit test for that, which tests equal expected frequencies by default, or other expected proportions typed in its Expected shares box).

Formulas and symbols

Category frequency

countk=#{i:xi=k}\text{count}_k = \#\{i : x_i = k\}

The number of rows falling into category k, plotted as that category's bar height.

Assumptions and checks

  • Bar heights here are always raw counts of non-missing values, so categories with different amounts of missing data or from samples of different sizes are not directly comparable as rates; the visual impression also depends on the sort order chosen (by count or alphabetical).

    In KernelStats: Not applicable: this is a visualization, not a statistical test; the card has no aggregation option (heights are always counts), and the caption states the number of categories and the most frequent one.

Alternatives

  • Histogram. The variable is continuous/numeric rather than categorical.
  • Chi-Square Goodness-of-Fit Test. You want a formal test of whether the observed category frequencies differ from equal frequencies by more than chance would explain, rather than just a visual summary; the card tests equal frequencies by default, or the expected shares you type in its Expected shares box.

Worked example

Scenario

Counting penguins by species across the full dataset.

Result

Adelie: 152, Gentoo: 124, Chinstrap: 68 (sorted largest first, the default Sort of auto).

Interpretation

Adelie is the most common species in this sample by a clear margin, and the sorted, descending order makes that dominance immediately visible without needing to read the exact counts off each bar.

Dataset: penguins.csv

Common misconceptions

Misconception

A bar chart and a histogram are basically the same kind of chart, just drawn slightly differently.

Correction

A bar chart's x-axis is categorical, with no inherent numeric order or bin width between bars. A histogram's x-axis is numeric, with equal-width bins whose order and spacing carry real meaning. Using a bar chart for continuous data (or a histogram for categories) misrepresents the structure of the underlying variable.

References

  1. NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.3.4 Bar chart, NIST/SEMATECH (2012), §1.3.3.4.