How to plot different grouped boxplots in a shared x axis with different dimensions that are inconsistent?
5 次查看(过去 30 天)
显示 更早的评论
Hi! I want to ask how to plot this 3 different grouped boxplots in a shared x-axis? because i plan to see the differences between them and add another secondary label to it. I want to make something like in the picture (attached), but I don't know how to make it work because i keep on having an error that says "dimensions of arrays being concatenated are not consistent".
close all; clear all; clc;
%--------------------------------------------------------------------------
% Data from 1mm
a = load ("All-1mm.txt");
b = load ("Origin-1mm.txt");
% Data from 2mm
c = load ("All-2mm.txt");
d = load ("Origin-2mm.txt");
% Data from 3mm
e = load ("All-3mm.txt");
f = load ("Origin-3mm.txt");
%--------------------------------------------------------------------------
figure
boxplot (a, b);
ylabel ("Displacement (m)");
title('1 mm Displacement');
% Set the x-axis tick labels
ax = gca;
ax.XAxis.TickLabelInterpreter = 'none'; % To display labels without interpreting LaTeX or special characters
ax.XAxis.TickLabels = {'X', 'Y', 'Z', 'Combined'}; % Assign secondary labels
figure
boxplot (c, d);
ylabel ("Displacement (m)");
title('2 mm Displacement');
% Set the x-axis tick labels
ax = gca;
ax.XAxis.TickLabelInterpreter = 'none'; % To display labels without interpreting LaTeX or special characters
ax.XAxis.TickLabels = {'X', 'Y', 'Z', 'Combined'}; % Assign secondary labels
figure
boxplot (e, f);
ylabel ("Displacement (m)");
title('3 mm Displacement');
% Set the x-axis tick labels
ax = gca;
ax.XAxis.TickLabelInterpreter = 'none'; % To display labels without interpreting LaTeX or special characters
ax.XAxis.TickLabels = {'X', 'Y', 'Z', 'Combined'}; % Assign secondary labels
0 个评论
采纳的回答
Cris LaPierre
2024-5-9
Here's a quick approach
cats = {'X', 'Y', 'Z', 'Combined'};
% Data from 1mm
a = load ("All-1mm.txt");
b = load ("Origin-1mm.txt");
A = [a,b];
g1 = repmat({'1 mm'},length(a),1);
% Data from 2mm
c = load ("All-2mm.txt");
d = load ("Origin-2mm.txt");
C = [c,d];
g2 = repmat({'2 mm'},length(c),1);
% Data from 3mm
e = load ("All-3mm.txt");
f = load ("Origin-3mm.txt");
E = [e,f];
g3 = repmat({'3 mm'},length(e),1);
data = [A;C;E];
G2 = cats(data(:,2));
G1 = [g1;g2;g3];
%--------------------------------------------------------------------------
figure
boxplot(data(:,1),{G1,G2},'FactorGap',[30])
ylabel ("Displacement (m)");
title('Displacement');
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!