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

280 views (last 30 days)

Show older comments

##### 0 Comments

### Answers (2)

Adam Danz
on 6 Mar 2020

Edited: Adam Danz
on 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)

##### 4 Comments

mhd z
on 10 Nov 2020

Thank you Adam

I ran the code line by line and figured it out. I was a little comlex :)

its realy a good code. thank you

Iddo Weiner
on 22 Mar 2017

##### 1 Comment

Francisco Javier Perez Sibaja
ongeveer 21 uur ago

Thanks for your contribution, it was useful to me!

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!