Insert two boxplots into one graph
11 ビュー (過去 30 日間)
古いコメントを表示
Hi, I would like to insert the two boxplots into one graph. How can I do this?
Here is the example code I use:
% first set
Q0_1 = -0.3771; % min
Q1_1 = -0.1007; % 25th percentile
Q2_1 = -0.0634; % 50th percentile (median)
Q3_1 = -0.0284; % 75th percentile
Q4_1 = 0.4958; % max
data_1 = [Q0_1 Q1_1 Q2_1 Q3_1 Q4_1];
data_1 = data_1(:, [1 2 2 3 4 4 5]);
boxplot_1 = boxplot(data_1.', 'Whisker', inf);
% SECOND set
Q0_2 = -0.2771; % min
Q1_2 = -0.1117; % 25th percentile
Q2_2 = -0.0428; % 50th percentile (median)
Q3_2 = -0.0311; % 75th percentile
Q4_2 = 0.3954; % max
data_2 = [Q0_2 Q1_2 Q2_2 Q3_2 Q4_2];
data_2 = data_2(:, [1 2 2 3 4 4 5]);
figure()
boxplot_2 = boxplot(data_2.', 'Whisker', inf);
% UNION
A = data_1';
B = data_2';
group = [ones(size(A)); 2 * ones(size(B))];
figure
boxplot([A; B], group)
set(gca,'XTickLabel',{'group A','group B'})
Trying the last few lines of code I get this graph but it doesn't represent what I want. How come?
0 件のコメント
採用された回答
Voss
2022 年 4 月 24 日
If you use the same parameters for the combined boxplot as you did for the individual ones (i.e., use 'Whisker', inf), does that represent what you want?
% first set
Q0_1 = -0.3771; % min
Q1_1 = -0.1007; % 25th percentile
Q2_1 = -0.0634; % 50th percentile (median)
Q3_1 = -0.0284; % 75th percentile
Q4_1 = 0.4958; % max
data_1 = [Q0_1 Q1_1 Q2_1 Q3_1 Q4_1];
data_1 = data_1(:, [1 2 2 3 4 4 5]);
boxplot_1 = boxplot(data_1.', 'Whisker', inf);
% SECOND set
Q0_2 = -0.2771; % min
Q1_2 = -0.1117; % 25th percentile
Q2_2 = -0.0428; % 50th percentile (median)
Q3_2 = -0.0311; % 75th percentile
Q4_2 = 0.3954; % max
data_2 = [Q0_2 Q1_2 Q2_2 Q3_2 Q4_2];
data_2 = data_2(:, [1 2 2 3 4 4 5]);
figure()
boxplot_2 = boxplot(data_2.', 'Whisker', inf);
% UNION
A = data_1';
B = data_2';
group = [ones(size(A)); 2 * ones(size(B))];
figure
boxplot([A; B], group, 'Whisker', inf)
set(gca,'XTickLabel',{'group A','group B'})
5 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



