How to combine boxplots from Anova into subplots
7 次查看(过去 30 天)
显示 更早的评论
I have three plots I want to combine this way but each anova1 produces 2 figures : a table and box plot and i'm not quite getting the box plots in the subplot as desired.
How do I combine the box plots into subplots.?
y = a(:,{'GRP_1','GRP_2','GRP_3','GRP_4'})
[p,tbl,stats] = anova1(y{:,:})
xlabel('xlabel')
ylabel('ylabel')
subplot(3,2,3)
y = b(:,{'GRP_1','GRP_2','GRP_3','GRP_4'})
[p,tbl,stats] = anova1(y{:,:})
xlabel('xlabel')
ylabel('ylabel')
subplot(3,3,3)
y = c(:,{'GRP_1','GRP_2','GRP_3','GRP_4'})
[p,tbl,stats] = anova1(y{:,:})
xlabel('xlabel')
ylabel('ylabel')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1384824/image.jpeg)
0 个评论
采纳的回答
Askic V
2023-5-16
Can the following example give you an ide how to solve the problem?
clear;clc;close all;
y1 = meshgrid(1:5);
%rng default; % For reproducibility
y1 = y1 + normrnd(0,1,5,5);
[p_1,tbl_1,stats_1] = anova1(y1)
y2 = meshgrid(1:5);
%rng default; % For reproducibility
y2 = y2 + normrnd(0,1,5,5);
[p_2,tbl_2,stats_2] = anova1(y2);
y3 = meshgrid(1:5);
%rng default; % For reproducibility
y3 = y3 + normrnd(0,1,5,5);
[p_3,tbl_3,stats_3] = anova1(y3)
h1 = figure(2);
h2 = figure(4);
h3 = figure(6);
% Create a new figure with subplots
figure
subplot(3, 1, 1)
% Copy the first figure into the first subplot
copyobj(allchild(get(h1, 'CurrentAxes')), gca)
title('Copied boxplot 1')
% Create the second subplot
subplot(3, 1, 2)
% Copy the second figure into the second subplot
copyobj(allchild(get(h2, 'CurrentAxes')), gca)
title('Copied boxplot 2')
% Create the third subplot
subplot(3, 1, 3)
% Copy the second figure into the second subplot
copyobj(allchild(get(h3, 'CurrentAxes')), gca)
title('Copied boxplot 3')
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!