Multiple box plot for 4 categories of three plots each.
3 views (last 30 days)
Show older comments
I currently have 12 boxplots on three different figures. Each figure contains 4 box plots each. I have attached one of the figures below.
![sf.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202012/sf.png)
I wanted to create multiple boxplot grouped into these 4 catagories: A,B,C and D. Ideally, I would like to create one figure that has three boxplots to A, three boxplots to group B, three boxplots to group C and three boxplots to group D. Hence, a total of 12 boxplots.
I have tried to look at other examples and functions such as multiple box plot, but none of them have worked so far. Primarily becasue my data points are not the same for each boxplot. For instance, I have 233 values for a2, 137 for a3 and 96 for a3. Here is my code:
% First group of 3 data sets
a2=(gaot.Placement);
a3=(gaom_t1.Placement);
a4=(gaom_t2.Placement);
% Second group of 3 data sets
b2=(gbot.Placement);
b3=(gbom_t1.Placement);
b4=(gbom_t2.Placement);
% Third group of 3 data sets
c2=(gcot.Placement);
c3=(gcom_t1.Placement);
c4=(gcom_t2.Placement);
% Fourth group of 3 data sets
d2=(gdot.Placement);
d3=(gdom_t1.Placement);
d4=(gdom_t2.Placement);
A={a2,a3,a4};
B={b2,b3,b4};
C={c2,c3,c4};
D={d2,d3,d4};
I would like to have a figure that has 12 boxplots grouped into plots of 3 in A,B,C and D. How may I do so?
Here is an example I found online and tried to implement but did not work.
x = [A,B,C,D];
group = [1,1,1,2,2,2,3,3,3,4,4,4];
positions = [1 1.25 1.75 2 2.25 2.75 3 3.25 3.75 4 4.25 4.75];
boxplot(x,group, 'positions', positions);
set(gca,'xtick',[mean(positions(1:3)) mean(positions(4:6)) mean(positions(7:9)) mean(positions(10:12))])
set(gca,'xticklabel',{'A','B','C','D'})
color = ['c', 'y', 'c', 'y'];
h = findobj(gca,'Tag','Box');
for j=1:length(h)
patch(get(h(j),'XData'),get(h(j),'YData'),color(j),'FaceAlpha',.5);
end
c = get(gca, 'positions');
hleg1 = legend(c(1:2), 'In group', 'Match', 'No match' );
Thank you!
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!