Bar Chart versus Histogram

A categorical bar chart with separated bars beside a histogram of a quantitative variable. The learner drags, sorts or shuffles the bars and sees that every bar keeps its height, then tries to move a histogram class: it is locked on the number line, and sorting the classes by count visibly breaks the axis and the shape. A frequency / relative-frequency switch rescales both charts.

Used in: Introduction to Statistics

Props

PropTypeDefaultDescription
titlestringBar chart versus histogramCard title.
categoriesstring[]["Spring", "Summer", "Fall", "Winter"]Category names of the categorical variable, in the order the data list them (up to 20). Pair with `counts`.
countsnumber[][40, 70, 60, 30]Frequency of each category (numbers >= 0, same length as `categories`). n is their sum; relative frequency = count / n.
variablestringFavorite seasonName of the categorical variable, shown under the bar chart's horizontal axis. Empty string hides it.
captionstring(none)Chart title shown above the bar chart, e.g. 'Nationalities of MLB Players Not Born in the US'.
scalestringfrequencyStarting vertical scale of both charts: 'frequency' (counts) or 'relative' (count / n). The bar heights stay the same; only the axis changes.
scaleTogglebooleantrueShow the Frequency / Relative switch in the title bar.
orderstringgivenStarting order of the bars: 'given' (as listed), 'alphabetical', 'descending' (largest first, a Pareto chart) or 'ascending'. Ties keep the given order.
reorderbooleantrueLet the learner reorder the bars (drag, order buttons, shuffle, move left/right). With false the bars can still be tapped to read their frequency.
selectedstring(none)Category that starts selected (highlighted, with its frequency and relative frequency in the readout).
showValuesbooleantruePrint each bar's value above it.
showHistogrambooleantrueShow the histogram panel beside the bar chart (stacked on phones). With false only the bar chart is shown, full width.
histogramEdgesnumber[][50, 60, 70, 80, 90, 100]Increasing class boundaries (cutpoints) of the histogram: k + 1 numbers for k classes [a, b), the last one closed. Used with `histogramCounts`, or to bin `histogramData`.
histogramCountsnumber[][3, 7, 15, 10, 5]Frequency of each histogram class (one fewer than `histogramEdges`). Default: 40 exam scores.
histogramDatanumber[](none)Raw quantitative observations; binned into `histogramEdges` if given, else into classes of width `histogramBinWidth`, else automatically. Overrides `histogramCounts`.
histogramBinWidthnumber(auto)Class width for binning `histogramData` when no `histogramEdges` are given.
histogramVariablestringExam scoreName (and unit) of the quantitative variable, shown under the histogram's axis. Default 'Exam score' for the default data, else 'Value'.
histogramCaptionstring(none)Chart title shown above the histogram, e.g. 'Weights of Enzyme Enhanced Eggs'.
sortHistogrambooleanfalseStart with the histogram's classes sorted by count (the 'what if' view that breaks the number line), as if the learner had switched it on.
seednumber1Seed of the Shuffle button's random orders (same seed, same sequence).
controlsstring[]all controls shownIds of the hideable controls to show (see the controls registry: toggle.scale, readout.relative, readout.shape); core controls always show. Omit to show everything. Fitted per page by component_scopes.py, not by hand. A page that starts on scale 'relative' keeps its relative axis without the switch; scaleToggle: false still hides the switch.