How to group boxplots on matlab

121 views (last 30 days)
Joyce Ai
Joyce Ai on 17 Jul 2020
Commented: Dennis on 21 Mar 2023
I want my box plots to be grouped like the following:
So far from all the forums I've seen, people are using actual numbers in the box plot function, whereas I am recalling all my data for the boxplot from the structs in my workspace, which is why I have not been able to follow along with some already existing forums.
This is my code:
figure('Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
m = boxplot([[LBPCAI_Block_RLlong].',[LBPCAI_Spring_RLlong].',[LBPCAI_Block_RLrectus].',[LBPCAI_Spring_RLrectus].',[LBPCAI_Block_RLgmed].',[LBPCAI_Spring_RLgmed].',[LBPCAI_Block_Rlongeo].',[LBPCAI_Spring_Rlongeo].',[LBPCAI_Block_Llongeo].',[LBPCAI_Spring_Llongeo].',[LBPCAI_Block_Rlongrectus].',[LBPCAI_Spring_Rlongrectus].',[LBPCAI_Block_Llongrectus].',[LBPCAI_Spring_Llongrectus].',[LBPCAI_Block_Rrectusgmed].',[LBPCAI_Spring_Rrectusgmed].',[LBPCAI_Block_Lrectusgmed].',[LBPCAI_Spring_Lrectusgmed].',[LBPCAI_Block_Reogmed].',[LBPCAI_Spring_Reogmed].',[LBPCAI_Block_Leogmed].',[LBPCAI_Spring_Leogmed].'],'labels',{'R:L Longissimus','R:L Rectus','R:L Gmed','R Longissimus:EO','L Longissimus:EO','R Longissimus:Rectus','L Longissimus:Rectus','R Rectus:Gmed','L Rectus:Gmed','R EO:Gmed','L EO:Gmed'});
title('Block Condition Muscle Co-activation');
ylabel('Muscle Co-Activation');
set (gca,'FontSize',16,'linew',1);
set(m,'LineWidth',2.3);
xtickangle(90);
There are 22 bars that should be plotted on the graph, which consists of 11 muscle pairings and their performances in a block and spring condition. I want the box plots to be grouped by the muscle pairs and the block and spring condition next to each other. So for example in the RLlong muscle pairing group, the two plots included should be the block and spring conditions.
I just cannot figure out how to format the boxplot code so that the plots are separated and grouped by muscle.
Any help would be greatly appreciated I am new to matlab and have been stuck on this forever :(

Answers (1)

Abdolkarim Mohammadi
Abdolkarim Mohammadi on 17 Jul 2020
boxchart is introduced in 2020a and is much more flexible than boxplot and has an option for plot grouping.
  1 Comment
Dennis
Dennis on 21 Mar 2023
Somehow the help for boxchart is not helpful if you have your data stored in a matrix. Is there a decent way to compare data stored in two matrices column by column? The easiest way I found was to use Excel or some other MSProduct.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!