# How do you create a grouped boxplot with categorical variables on the x-axis.

106 visualizzazioni (ultimi 30 giorni)
Jessica Ritz il 22 Mar 2017
Included is a picture of what I'm trying to do. I downloaded some new functions off of MatLab downloads but they seem to be for numerical variables on both the x and y-axis. I'm looking to group categorical variables on the x-axis of the boxplot. Is there anything I can download or any existing code that does this? Thanks in advance!
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (2)

Adam Danz il 6 Mar 2020
Modificato: Adam Danz il 6 Mar 2020
If your boxplot data are matrices with the same number of columns, you can use boxplotGroup() from the file exchange to group the boxplots together with space between the groups.
For example,
data = {rand(100,2), rand(100,2)+.2, rand(100,2)-.2};
boxplotGroup(data, 'PrimaryLabels', {'a' 'b' 'c'}, ...
'SecondaryLabels',{'Group1', 'Group2'}, 'GroupLabelType', 'Vertical')
Example 2
data = {rand(100,2), rand(100,2)+.2, rand(100,2)-.2};
boxplotGroup(data, 'PrimaryLabels', {'a' 'b' 'c'}, ...
'SecondaryLabels',{'Group1', 'Group2'}, 'InterGroupSpace', 2)
Also see Kelly Kearney's boxplot2() function.
##### 4 CommentiMostra 2 commenti meno recentiNascondi 2 commenti meno recenti
Adam Danz il 8 Nov 2020
This is from the documentation (current vs.1.2.2).
boxplotGroup(x) receives a 1xm cell array where each element is a matrix with n columns and produced n groups of boxplot boxes with m boxes per group.
So for this input below, there will be 4 groups of 3 boxplots within each group because there are 3 elements of the cell array and each element has 4 columns. That's how you should think about organizing your data.
data = {rand(100,4), rand(20,4)*.8, rand(1000,4)*1.2}
data = 1x3 cell array
{100×4 double} {20×4 double} {1000×4 double}
boxplotGroup(data)
It sounds like what you want is,
g{1} = data(1:100, 1:4:end); % or 1:4:9
g{2} = data(1:100, 2:4:end); % or 2:4:10
g{3} = data(1:100, 3:4:end); % etc.....
g{4} = data(1:100, 4:4:end);
mhd z il 10 Nov 2020
I ran the code line by line and figured it out. I was a little comlex :)
its realy a good code. thank you

Accedi per commentare.

Iddo Weiner il 22 Mar 2017
Take a look at this, it explains how to do precisely what you want: Link
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Thanks for your contribution, it was useful to me!

Accedi per commentare.

### Categorie

Scopri di più su Box Plots in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by