Перейти к содержанию

Статистика · Начальный

Read and create histograms, box plots and violin plots

Show distribution shape with appropriate bins, quartiles, density estimates and observations.

10 мин чтения · 26 окт. 2026 г.

Эта страница ещё не переведена, поэтому вы читаете английскую версию.

Главное

  • Explain bin and whisker choices.
  • Avoid overinterpreting small sample smoothing.
  • Document transformations.
Содержание

Show distribution shape with appropriate bins, quartiles, density estimates and observations.

An average does not tell readers how observations are distributed. A group may be tightly concentrated, widely spread, strongly skewed or divided into several patterns. Distribution plots help expose these features and make it easier to judge whether the chosen statistical summary answers the question.

This tutorial develops three common displays: histograms, box plots and violin plots. It also explains when individual points or a cumulative display may be more informative. The goal is to help you describe the data faithfully, not to make every dataset look normal or every comparison look dramatic.

Understand the features you are trying to show

A distribution describes how values are spread across possible outcomes. Location refers to a central or typical value. Dispersion refers to variability. Skewness describes asymmetry, and a mode is a region where observations are relatively concentrated. A long right tail contains unusually large values relative to most observations.

These features have substantive meanings. In a hypothetical engineering study, a long tail of completion times may identify occasional severe delays that an average hides. In a hypothetical ecology study, a second cluster of plant sizes may reflect age groups or environmental differences. In a social survey, scores concentrated at the maximum may indicate a ceiling in the instrument rather than universal success.

Ask which unit produced the values. A distribution of 2,000 cells from four donors is a cell distribution, not a distribution from 2,000 independent donors. Displaying all cells can be useful, but the caption and analysis must preserve that hierarchy.

Construct a histogram step by step

A histogram divides a numeric scale into intervals called bins and counts or summarises observations within each interval. Unlike a categorical bar chart, adjacent bins represent contiguous regions of the measurement scale. NIST describes common histogram normalisations and the features these displays help reveal. S31

For a simple workflow:

  1. Confirm the variable, unit and valid measurement range.
  2. Check missing values, impossible values and repeated observations.
  3. Choose a set of bin boundaries with a stated inclusion convention.
  4. Decide whether the vertical axis should show count, proportion or density.
  5. Inspect several reasonable bin widths before choosing the final display.
  6. Use common boundaries when comparing groups on the same scale.

Consider eight synthetic waiting times: 1, 2, 2, 3, 4, 4, 5 and 9 minutes. Using bins from 0 up to but not including 3, from 3 up to but not including 6, and from 6 through 9 inclusive gives counts of 3, 4 and 1. The final boundary rule must include the value 9. Otherwise a software setting could accidentally omit it or move it to an additional bin.

A narrower set of bins would reveal more detail, but with eight values the apparent peaks would be unstable. A dot plot displaying all eight measurements may be easier to understand. A histogram becomes more useful when there are enough observations to support a shape rather than isolated counts.

Distinguish frequency from density

A frequency histogram has counts on the vertical axis. A relative frequency histogram divides each count by the total number of observations. A density histogram also divides by the bin width, so the area of each bar represents the proportion in that interval.

For the first bin in the synthetic waiting time example, density is 3 divided by 8 divided by 3, or 0.125 per minute. Multiplying that height by the width of 3 minutes gives an area of 0.375, the fraction of observations in the bin. A density height is not itself a probability, and density values can exceed one when the scale and concentration permit it.

This distinction matters particularly with unequal bin widths. Plotting raw counts as heights for bins of unequal width can make wider intervals appear more concentrated simply because they cover more possible values. If using density, label it and explain the units. Do not switch between counts and density in adjacent panels without making the change explicit.

Treat bin choice as an analytical decision

A histogram's shape can change with both bin width and the position of the first boundary. Very broad bins conceal structure. Very narrow bins can make sampling noise resemble several populations. There is no single bin width that reveals the truth for every dataset.

Use a reasonable default or rule as a starting point, then inspect whether your interpretation survives nearby choices. Do not search for a width that makes a desired separation appear. If a scientific conclusion depends on a particular visual boundary, evaluate it with an appropriate analysis rather than relying on the graphic alone.

For group comparisons, common bin edges prevent apparent differences created by formatting. If groups have different sample sizes, counts emphasise both distribution and sample size, while density emphasises relative shape. Choose deliberately and state the group sample sizes either way.

Read box plots using the actual convention

A conventional box spans the lower and upper quartiles, with a line at the median. The interquartile range, or IQR, equals the upper quartile minus the lower quartile. It describes the middle half of the distribution. Whisker rules vary, so a legend must name the rule used. NIST describes both full range and fenced variants. S30

One common convention extends whiskers to the most extreme observed values within 1.5 IQR beyond the box. Observations beyond those limits appear separately. These points are unusual relative to that rule; they are not automatically erroneous, scientifically irrelevant or eligible for exclusion.

Quartile algorithms can differ, especially in small samples. For the eight waiting times above, using the median of each half gives a lower quartile of 2, a median of 3.5 and an upper quartile of 4.5 minutes. The IQR is 2.5 minutes. The upper fence is 8.25 minutes, so 9 is marked beyond the whisker under this convention. Other software quantile definitions may give different quartiles. Record the software and relevant settings rather than assuming all implementations coincide.

A box plot hides how many values occupy particular regions inside the box. Overlay points for small samples. A group with two distinct clusters can have a box similar to a unimodal group. If that distinction matters, a distribution display or individual observations should accompany the summary.

Understand what a violin plot estimates

A violin plot mirrors a smoothed density estimate around a central axis. Its shape is estimated rather than directly observed. A bandwidth controls how much smoothing occurs: small values retain more local variation, while large values merge nearby features. Software may scale violins to equal areas, equal maximum widths or a quantity related to sample size. The ggplot2 documentation identifies these controls explicitly. S405

A wide part of one violin does not necessarily mean that group has more observations than another. Under equal area scaling, each shape has the same area regardless of sample size. Report the scaling and put sample sizes in the figure or caption.

Density estimates can also extend beyond physically possible values, such as negative completion times. Use appropriate boundaries or a more suitable display and explain the choice. Trimming a violin to the observed range changes its visible outline; it does not solve every boundary estimation problem.

With a very small sample, a polished violin can imply more knowledge than the data support. Individual points with a median or other useful summary may be more honest. Adding points to a violin helps readers see which parts of the smooth shape have observational support.

The same synthetic observations are shown as a histogram, a box plot with points and a violin plot with points.

These three views use one supplied synthetic dataset. They are alternative descriptions of the same observations, not three independent confirmations of a finding.

Consider transformations and cumulative displays

Positive measurements spanning several orders of magnitude may be easier to inspect on a logarithmic scale. State whether the values were transformed before calculating summaries or only the axis was transformed. A mean calculated after taking logarithms is not the arithmetic mean of the original values.

Explain zeros and negative values. Adding a constant changes relative differences most strongly near zero and requires a rationale. Do not silently drop zeros to allow a logarithmic plot. Where an instrument reports a detection limit, distinguish a below detection measurement from a true zero.

An empirical cumulative distribution function, or ECDF, shows the fraction of observations at or below each value. It avoids histogram bins and density bandwidths. For the eight waiting times, six of eight are at or below 4 minutes, so the cumulative fraction there is 0.75. This representation can directly answer a question such as “What fraction of tasks finishes within four minutes?”

A cumulative display still needs context. If times are censored because some tasks had not finished when observation stopped, simply plotting completed times can be misleading. Event time methods, discussed in the advanced plots article, may be needed.

Separate visual diagnosis from statistical inference

A histogram that looks roughly symmetric does not prove that a normal model is correct. A small sample may reveal little about tails, and a large dataset may show departures that do not invalidate every method. Check the assumptions of the analysis you actually use. For a paired t procedure, for example, the relevant normality assumption concerns differences under the model, not two separate raw group histograms.

Likewise, visibly separated boxes are not automatically a significance test. Report the intended effect estimate and its uncertainty. A descriptive figure helps readers examine the data; the inferential procedure must address the scientific question and dependency structure.

For an engineering specification, a reference line at an acceptable limit may be more useful than a generic p value. For a social science scale, explain the scoring range and whether ordinal categories are being treated as approximately continuous. These decisions should appear in Methods rather than remaining hidden in the plot settings.

Write a legend and interpretation that match

For a hypothetical waiting time study, a useful legend might be:

Points show eight synthetic waiting times in minutes. The box uses the median of each half to define quartiles and marks the median at 3.5 minutes. Whiskers end at observations within 1.5 IQR of the quartiles; the value at 9 minutes lies beyond the upper whisker. All values remain in the analysis. The example illustrates display conventions and is not a real service evaluation.

A suitable interpretation is: “Most constructed times lie between 1 and 5 minutes, with one longer value at 9 minutes. The plot alone cannot establish whether that value is a recording error, a different process or ordinary variability.” This is more useful than “The outlier was removed to improve the distribution.”

Practice and model answer

Task: A violin for five observations looks bimodal. Can you conclude that two subpopulations exist?

Model answer: No. Check the actual values and how the shape changes with reasonable bandwidth choices. With five observations, the smooth outline can be unstable. A claim about subpopulations needs substantive evidence and an appropriate analysis, ideally with additional independent data.

Task: One group has 20 observations and another has 200. Their equal area violins have the same maximum width. Do they have the same sample size or uncertainty?

Model answer: Neither follows. Equal area is a display convention. Report the actual sample sizes and calculate uncertainty for the relevant effect using the design, including any clustering. The widths do not provide that calculation.

Sources

S31: National Institute of Standards and Technology. Histogram. NIST/SEMATECH e Handbook of Statistical Methods, section 1.3.3.14. Accessed 11 November 2026.

S30: National Institute of Standards and Technology. Box Plot. NIST/SEMATECH e Handbook of Statistical Methods, section 1.3.3.7. Accessed 11 November 2026.

S405: ggplot2 authors. Violin plot: geom_violin. Official package documentation. Accessed 11 November 2026.

Файлы

Войдите, чтобы скачать эти файлы.