How to combine boxplots from Anova into subplots

1 visualizzazione (ultimi 30 giorni)
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')

Risposta accettata

Askic V
Askic V il 16 Mag 2023
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)
p_1 = 1.4519e-06
tbl_1 = 4×6 cell array
{'Source' } {'SS' } {'df'} {'MS' } {'F' } {'Prob>F' } {'Columns'} {[39.6115]} {[ 4]} {[ 9.9029]} {[ 18.8637]} {[1.4519e-06]} {'Error' } {[10.4994]} {[20]} {[ 0.5250]} {0×0 double} {0×0 double } {'Total' } {[50.1109]} {[24]} {0×0 double} {0×0 double} {0×0 double }
stats_1 = struct with fields:
gnames: [5×1 char] n: [5 5 5 5 5] source: 'anova1' means: [1.6128 2.3200 3.0249 4.4757 4.9313] df: 20 s: 0.7245
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)
p_3 = 4.8063e-05
tbl_3 = 4×6 cell array
{'Source' } {'SS' } {'df'} {'MS' } {'F' } {'Prob>F' } {'Columns'} {[41.2169]} {[ 4]} {[ 10.3042]} {[ 11.6368]} {[4.8063e-05]} {'Error' } {[17.7098]} {[20]} {[ 0.8855]} {0×0 double} {0×0 double } {'Total' } {[58.9267]} {[24]} {0×0 double} {0×0 double} {0×0 double }
stats_3 = struct with fields:
gnames: [5×1 char] n: [5 5 5 5 5] source: 'anova1' means: [0.9619 2.4276 2.8681 3.7721 4.7765] df: 20 s: 0.9410
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')

Più risposte (0)

Categorie

Scopri di più su Data Distribution Plots in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by