View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Hierarchically grouped boxplot

4.8 | 4 ratings Rate this file 6 Downloads (last 30 days) File Size: 3.26 KB File ID: #40878 Version:
image thumbnail

Hierarchically grouped boxplot


Matt Tearle (view profile)


22 Mar 2013 (Updated )

A modification to boxplot that shows the hierarchical relationships between the grouping variables.

| Watch this File

File Information

HIERARCHICALBOXPLOT(X,GRP) creates a boxplot of the data in X, grouped according to the grouping variables represented by the columns of GRP. The groupings are shown hierarchically, with the groups in each column of GRP being shown as groups within the groups of the next column.
Known limitation: BOXPLOT readjusts the label positions whenever the figure is resized (including docking/undocking). HIERARCHICALBOXPLOT does *not*. Too much resizing may cause strange-looking label positions.


This file inspired Alternative Box Plot.

Required Products Statistics and Machine Learning Toolbox
MATLAB release MATLAB 8.0 (R2012b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
23 Sep 2016 Matt Tearle

Matt Tearle (view profile)

Hi Rita. Thanks for the feedback. Unfortunately, I built this on top of the regular boxplot function, which imposed a number of restrictions I couldn't find my way around, hence the error message about not being able to handle groups with no data. With some of the new data analysis functionality in MATLAB, I might be able to rebuild this function from scratch.

With respect to plotting two sets of data, what would your desired result be? Are you thinking of plotting x with groups g, then adding y with the same groups g? In which case, would you want the y boxes next to the x ones (in a different color or something)? Or directly on top (with some transparency, presumably)? Again, there's no good way to do this right now, but I'd like to consider enhancements if I rebuild it.

Comment only
22 Sep 2016 Rita

Rita (view profile)

Thanks Matt, How I can add another set of data to the plot .I mean plot this box plot and then to compare I add "hold on" and plot another boxplot in the same graph

Comment only
22 Sep 2016 Rita

Rita (view profile)

Thanks for the function.I got an error "Error using hierarchicalBoxplot (line 86)
Some of the group combinations had no data and hierarchicalBoxplot can't cope with that.

Comment only
19 Feb 2015 Matt Tearle

Matt Tearle (view profile)

Hi Juan (& Arnold -- sorry, for some reason I never saw your comments before)

Thanks for your feedback. Unfortunately there's no easy way to change things because, to be blunt, my code is a pile of pretty hideous hacks on top of boxplot. You could certainly hack my hacks for a specific purpose, but I don't know if there's a good way to do so generally.

I like the idea of using color. Do you have an idea of what the function interface would look like for using color instead of separator lines? I'm wondering about an optional cell array of n strings (n = number of grouping variables) that could be something like 'color', 'backgroundcolor', 'line', or 'none'. But that way you couldn't specify *what* the colors were, unless you could give another array of colors. But that seems a bit tedious. Any thoughts?

Comment only

Hi Matt,

Thank you for this code. I wonder if you could give me a hand with this. First, I would like to use background color instead of lines for separating my groups. Second, I would like to substract the first line of ticks. Let me try to be clearer with this part. Taking the plot you have as an example, I would like to substract "70 76 82 70 76 82 70 76 82" just from the ticks.

I really appreciate your help.


Comment only

28 Jul 2014 arnold

arnold (view profile)

Hi Matt, I was wondering if you might have a chance to include coloring+legend as another dimension. Otherwise... using it every week. Regards Arnold

Comment only
26 Jan 2014 arnold

arnold (view profile)

Hi Matt,
thanks for the function. This is really missing in Matlab.
A couple of thoughts that might make it even better:

The ability to plot the lowest hierarchy/dimension as different box-color, or maybe second y-axis. This is closely related to the second idea:
The ability to plot 2-y axis, differentiated by color as well. Many applications have two different variables you might wanna show.

3. It would be more usable if one could simply feed it a table. The new 'table' data type looks like it would for great with this.

18 Oct 2013 Eric Sampson

26 Apr 2013 DAEJIN

DAEJIN (view profile)

25 Mar 2013 1.1

Copyright info

01 Sep 2016

Updated license

Contact us