Alternative box plot

Draw a box plot with various display options

10.1K Downloads

Updated 5 May 2018

From GitHub

View License on GitHub

Editor's Note: This file was selected as MATLAB Central Pick of the Week

NOTE: this function is now available from the IoSR Matlab Toolbox as iosr.statistics.boxPlot.
-------------------------
Alternative box plot function for Matlab with many options. These options include:
- Variable sample sizes (via the tab2box() function).
- Show box sample size.
- Scaled or uniform box spacing.
- Box width scaled by sample size.
- Overlay scatter plots of underlying data.
- Overlay the mean of the data.
- Overlay additional percentiles, and attach labels to them.
- Hierarchical X-labeling and support for multidimensional data.
- Notched boxes.
- Vertical lines to separate groups.
- Automated construction of a legend.
- Set box limits as percentiles.
- Set whisker extent via various methods.
- Use of weighted quantiles.
- Creation of violin plots.

Cite As

Christopher Hummersone (2023). Alternative box plot (https://github.com/IoSR-Surrey/MatlabToolbox), GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2015a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: notBoxPlot, Hierarchically grouped boxplot

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Versions that use the GitHub default branch cannot be downloaded

Version Published Release Notes
3.2.1.0

Updated version number.
Updated description.
Added acknowledgement.
Moved function in to updated toolbox.
Function now natively supports sub-groups, handles NaNs more robustly, and returns sample size(s). A few other minor tweaks and doc changes.

3.1.1.0

Added percentile options for box and whisker extent. Modified help to clarify scatter plotting.
Moved file to Github.

3.1.0.0

Added 'theme' property to allow multiple display properties to be changed simultaneously. Various bug fixes.

3.0.2.0

More bug fixes. Forced legend alpha to match box alpha.

3.0.1.0

Added ability to specify colors as a colormap function. Changed some size properties to no longer be specifiable for each group. Bug fixes.

3.0.0.0

Re-implemented function as a class (with a new name). Added property to automate construction of a legend.

2.0.8.0

Added meanSize property.

2.0.7.0

Corrected calculation of mean when data include NaN. Updated picture.

2.0.6.0

Added options for displaying the means.

2.0.5.0

Added trap for MarkerEdgeAlpha (scatterAlpha), which older versions of Matlab do not support.

2.0.4.0

Added layer and transparency options.

2.0.3.0

Fixed automatic placement of boxes.

2.0.2.0

Corrected bug where x offset was erroneous if y was not hierarchical.

2.0.1.0

Small tweaks to improve robustness.

2.0.0.0

Numerous changes to interface in order to support multidimensional data and improve hierarchical data labelling. Added scaleWidth option to scale box widths according to sample size.

1.6.3.0

Added x-shaping to outliers and tweaked offset distribution.

1.6.2.0

Added x shaping for overlayed scatter plots whereby the random x offset is related to the data distribution. Fixed bug whereby xSeparator handle would be sought even if xSeparator was not specified.

1.6.1.0

Shuffled a few things around so that the creation order defines the layering, rather than relying on uistack(). Added linkprop() and listener to keep axes in sync and to change xseparator if ylim changes.

1.6.0.0

Added options to: overlay a scatter plot of the underlying data, display the sample size in each box, add x-group separators, and add hierarchical labelling. Shuffled outputs slightly. Thanks to Arnold for the suggestions.
Forgot to include tab2box.
Updated image.

1.5.1.0

Fixed bug where x is a cell array of strings.

1.5.0.0

Remove NaN from x data (and corresponding y data).

1.4.1.0

Updated documentation.

1.4.0.0

Improved robustness to small or empty samples. Add tab2box function for arranging tabular into the format accepted by box_plot.

1.3.0.0

Function now natively supports sub-groups, handles NaNs more robustly, and returns sample size(s). A few other minor tweaks and doc changes.

1.2.0.0

Moved quantile calculation to new function.

1.1.0.0

Changed/corrected quantile estimation algorithm. Details in help text.

1.0.0.0

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.