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
| Prop | Type | Default | Description |
|---|---|---|---|
| title | string | Bar chart versus histogram | Card title. |
| categories | string[] | ["Spring", "Summer", "Fall", "Winter"] | Category names of the categorical variable, in the order the data list them (up to 20). Pair with `counts`. |
| counts | number[] | [40, 70, 60, 30] | Frequency of each category (numbers >= 0, same length as `categories`). n is their sum; relative frequency = count / n. |
| variable | string | Favorite season | Name of the categorical variable, shown under the bar chart's horizontal axis. Empty string hides it. |
| caption | string | (none) | Chart title shown above the bar chart, e.g. 'Nationalities of MLB Players Not Born in the US'. |
| scale | string | frequency | Starting vertical scale of both charts: 'frequency' (counts) or 'relative' (count / n). The bar heights stay the same; only the axis changes. |
| scaleToggle | boolean | true | Show the Frequency / Relative switch in the title bar. |
| order | string | given | Starting order of the bars: 'given' (as listed), 'alphabetical', 'descending' (largest first, a Pareto chart) or 'ascending'. Ties keep the given order. |
| reorder | boolean | true | Let the learner reorder the bars (drag, order buttons, shuffle, move left/right). With false the bars can still be tapped to read their frequency. |
| selected | string | (none) | Category that starts selected (highlighted, with its frequency and relative frequency in the readout). |
| showValues | boolean | true | Print each bar's value above it. |
| showHistogram | boolean | true | Show the histogram panel beside the bar chart (stacked on phones). With false only the bar chart is shown, full width. |
| histogramEdges | number[] | [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`. |
| histogramCounts | number[] | [3, 7, 15, 10, 5] | Frequency of each histogram class (one fewer than `histogramEdges`). Default: 40 exam scores. |
| histogramData | number[] | (none) | Raw quantitative observations; binned into `histogramEdges` if given, else into classes of width `histogramBinWidth`, else automatically. Overrides `histogramCounts`. |
| histogramBinWidth | number | (auto) | Class width for binning `histogramData` when no `histogramEdges` are given. |
| histogramVariable | string | Exam score | Name (and unit) of the quantitative variable, shown under the histogram's axis. Default 'Exam score' for the default data, else 'Value'. |
| histogramCaption | string | (none) | Chart title shown above the histogram, e.g. 'Weights of Enzyme Enhanced Eggs'. |
| sortHistogram | boolean | false | Start 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. |
| seed | number | 1 | Seed of the Shuffle button's random orders (same seed, same sequence). |
| controls | string[] | all controls shown | Ids 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. |