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

299 ビュー (過去 30 日間)
Jessica Ritz
Jessica Ritz 2017 年 3 月 22 日
コメント済み: mhd z 2020 年 11 月 10 日
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!

回答 (2 件)

Adam Danz
Adam Danz 2020 年 3 月 6 日
編集済み: Adam Danz 2020 年 3 月 6 日
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 件のコメント
mhd z
mhd z 2020 年 11 月 10 日
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
Iddo Weiner 2017 年 3 月 22 日
Take a look at this, it explains how to do precisely what you want: Link

Community Treasure Hunt

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

Start Hunting!

Translated by