How to Switch order of Boc plots
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
The Code I have is attached I would like to switch the placements of Adaptive and No Tag
load('comedyworkspace.mat')
% Color Set
color_grey = [0.55,0.55,0.55];
green.fill = 1.08*[195,214,155]/255;
green.light = 0.9*[195,214,155]/255;
green.dark = 0.7*[195,214,155]/255;
purple.fill = 1.08*[179,162,199]/255;
purple.light = 0.9*[179,162,199]/255;
purple.dark = 0.7*[179,162,199]/255;
orange.fill = 1.06*[239,111,68]/255;
orange.light = 0.9*[239,111,68]/255;
orange.dark = 0.7*[239,111,68]/255;
blue.fill = 1.12*[142,180,227]/255;
blue.light = 0.9*[142,180,227]/255;
blue.med = 0.7*[142,180,227]/255;
blue.dark = 0.5*[142,180,227]/255;
red.dark = [153,0,0]/255;
red.fill = [255,102,102]/255;
%% Prep axes
figure
subplot(2,2,1)
hold on; grid on;
set(gca, 'YGrid', 'on', 'XGrid', 'off')
s1=Competence{1:15, 1};
s2=Competence{1:15, 2};
s3=Competence{1:15, 3};
%s5=mean(s1);
%s6=mean(s2);
%s7=mean(s3);
ColorOrder=[red.dark;blue.light;green.dark;purple.dark];
line_width=1.0;
b = boxchart(ones(1, length(s1)), s1);
set(b, 'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 1), ...
'BoxFaceColor', ColorOrder(:, 1))%,...
%'MarkerEdgeColor', green.dark);
set(findobj(gcf,'-regexp','Tag','\w*Whisker'),'LineStyle','-')
median = findobj(gcf, 'type', 'line', 'Tag', 'Median');
set(median, 'Color', color_grey, 'LineWidth', line_width);
boxchart(ones(1, length(s1)), s1, ...
'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 1), ...
'BoxFaceColor', ColorOrder(:, 1));
boxchart(2 * ones(1, length(s2)), s2, ...
'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 2), ...
'BoxFaceColor', ColorOrder(:, 2));
boxchart(3 * ones(1, length(s3)), s3, ...
'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 3), ...
'BoxFaceColor', ColorOrder(:, 3));
%'MarkerEdgeColor', green.dark);
set(findobj(gcf,'-regexp','Tag','\w*Whisker'),'LineStyle','-')
median = findobj(gcf, 'type', 'line', 'Tag', 'Median');
set(median, 'Color', color_grey, 'LineWidth', line_width);
hold on
%% Final axes labels and options
title('Competence');
xticks(1:3)
xticklabels({'Adaptive', 'Hardcoded', 'No Tag'})
xtickangle(45)
ylim([0 9])
yticks(1:9)
yticklabels({'1', '2', '3', '4', '5', '6', '7','8','9'})
ylabel('Rating')
% yline(1,'color',color_grey,'LineWidth',1);
hold on
scatter(1,mean(Competence{2:15,2}),"+")
scatter(2,mean(Competence{2:16,2}),"+")
scatter(3,mean(Competence{2:15,2}),"+")
% plot([s5 s6 s7 ], 'db');
hold off
hold on
subplot(2,2,2)
hold on; grid on;
set(gca, 'YGrid', 'on', 'XGrid', 'off')
s1=Warmth{1:15, 1};
s2=Warmth{1:15, 2};
s3=Warmth{1:15, 3};
%s5=mean(s1);
%s6=mean(s2);
%s7=mean(s3);
ColorOrder=[red.dark;blue.light;green.dark;purple.dark];
line_width=1.0;
b = boxchart(ones(1, length(s1)), s1);
set(b, 'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 1), ...
'BoxFaceColor', ColorOrder(:, 1))%,...
%'MarkerEdgeColor', green.dark);
set(findobj(gcf,'-regexp','Tag','\w*Whisker'),'LineStyle','-')
median = findobj(gcf, 'type', 'line', 'Tag', 'Median');
set(median, 'Color', color_grey, 'LineWidth', line_width);
boxchart(ones(1, length(s1)), s1, ...
'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 1), ...
'BoxFaceColor', ColorOrder(:, 1));
boxchart(2 * ones(1, length(s2)), s2, ...
'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 2), ...
'BoxFaceColor', ColorOrder(:, 2));
boxchart(3 * ones(1, length(s3)), s3, ...
'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 3), ...
'BoxFaceColor', ColorOrder(:, 3));
%'MarkerEdgeColor', green.dark);
set(findobj(gcf,'-regexp','Tag','\w*Whisker'),'LineStyle','-')
median = findobj(gcf, 'type', 'line', 'Tag', 'Median');
set(median, 'Color', color_grey, 'LineWidth', line_width);
%% Final axes labels and options
title('Warmth');
xticks(1:3)
xticklabels({'Adaptive', 'Hardcoded', 'No Tag'})
xtickangle(45)
ylim([0 9])
yticks(1:9)
yticklabels({'1', '2', '3', '4', '5', '6', '7','8','9'})
ylabel('Rating')
% yline(1,'color',color_grey,'LineWidth',1);
hold on
scatter(1,mean(Warmth{2:19,2}),"+")
scatter(2,mean(Warmth{2:16,2}),"+")
scatter(3,mean(Warmth{2:15,2}),"+")
% plot([s5 s6 s7 ], 'db');
hold on
%% Prep axes
subplot(2,2,3)
hold on; grid on;
set(gca, 'YGrid', 'on', 'XGrid', 'off')
s1=Discomfort{1:15, 2};
s2=Discomfort{1:15, 3};
s3=Discomfort{1:15, 4};
%s5=mean(s1);
%s6=mean(s2);
%s7=mean(s3);
ColorOrder=[red.dark;blue.light;green.dark;purple.dark];
line_width=1.0;
b = boxchart(ones(1, length(s1)), s1);
set(b, 'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 1), ...
'BoxFaceColor', ColorOrder(:, 1))%,...
%'MarkerEdgeColor', green.dark);
set(findobj(gcf,'-regexp','Tag','\w*Whisker'),'LineStyle','-')
median = findobj(gcf, 'type', 'line', 'Tag', 'Median');
set(median, 'Color', color_grey, 'LineWidth', line_width);
boxchart(ones(1, length(s1)), s1, ...
'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 1), ...
'BoxFaceColor', ColorOrder(:, 1));
boxchart(2 * ones(1, length(s2)), s2, ...
'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 2), ...
'BoxFaceColor', ColorOrder(:, 2));
boxchart(3 * ones(1, length(s3)), s3, ...
'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 3), ...
'BoxFaceColor', ColorOrder(:, 3));
%'MarkerEdgeColor', green.dark);
set(findobj(gcf,'-regexp','Tag','\w*Whisker'),'LineStyle','-')
median = findobj(gcf, 'type', 'line', 'Tag', 'Median');
set(median, 'Color', color_grey, 'LineWidth', line_width);
hold on
%% Final axes labels and options
title('Discomfort');
xticks(1:3)
xticklabels({'Adaptive', 'Hardcoded', 'No Tag'})
xtickangle(45)
ylim([0 9])
yticks(1:9)
yticklabels({'1', '2', '3', '4', '5', '6', '7','8','9'})
ylabel('Rating')
% yline(1,'color',color_grey,'LineWidth',1);
hold on
scatter(1,mean(Discomfort{2:19,2}),"+")
scatter(2,mean(Discomfort{2:16,2}),"+")
scatter(3,mean(Discomfort{2:15,2}),"+")
% plot([s5 s6 s7 ], 'db');
hold off
hold on
print('-dpng', '-r300', 'plotting_example');
0 comentarios
Respuestas (1)
Voss
el 2 de Jul. de 2023
In order to swap the first boxchart ("Adaptive") with the third boxchart ("No Tag"), swap their xgroupdata (which is the first argument to boxchart); that is, give "Adaptive" xgroupdata = 3 and give "No Tag" xgroupdata = 1. Also do the same for the scatter plots of the means. And of course change the order of xticklabels.
I'll illustrate the old and new order - just for the "Competence" boxchart - below; you can apply the same changes to the "Warmth" and "Discomfort" boxcharts.
% a Competence variable that seems like what you're using:
Competence = array2table(9*rand(16,3));
This stuff doesn't change:
% Color Set
color_grey = [0.55,0.55,0.55];
green.fill = 1.08*[195,214,155]/255;
green.light = 0.9*[195,214,155]/255;
green.dark = 0.7*[195,214,155]/255;
purple.fill = 1.08*[179,162,199]/255;
purple.light = 0.9*[179,162,199]/255;
purple.dark = 0.7*[179,162,199]/255;
orange.fill = 1.06*[239,111,68]/255;
orange.light = 0.9*[239,111,68]/255;
orange.dark = 0.7*[239,111,68]/255;
blue.fill = 1.12*[142,180,227]/255;
blue.light = 0.9*[142,180,227]/255;
blue.med = 0.7*[142,180,227]/255;
blue.dark = 0.5*[142,180,227]/255;
red.dark = [153,0,0]/255;
red.fill = [255,102,102]/255;
%% Prep axes
figure
subplot(1,2,1)
hold on; grid on;
set(gca, 'YGrid', 'on', 'XGrid', 'off')
s1=Competence{1:15, 1};
s2=Competence{1:15, 2};
s3=Competence{1:15, 3};
ColorOrder=[red.dark;blue.light;green.dark;purple.dark];
line_width=1.0;
The old order:
boxchart(ones(1, length(s1)), s1, ...
'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 1), ...
'BoxFaceColor', ColorOrder(:, 1));
boxchart(2 * ones(1, length(s2)), s2, ...
'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 2), ...
'BoxFaceColor', ColorOrder(:, 2));
boxchart(3 * ones(1, length(s3)), s3, ...
'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 3), ...
'BoxFaceColor', ColorOrder(:, 3));
hold on
scatter(1,mean(Competence{2:15,2}),"+")
scatter(2,mean(Competence{2:16,2}),"+")
scatter(3,mean(Competence{2:15,2}),"+")
xticklabels({'Adaptive', 'Hardcoded', 'No Tag'})
This stuff doesn't change:
%% Final axes labels and options
title('Competence - Old Order');
xticks(1:3)
xtickangle(45)
ylim([0 9])
yticks(1:9)
yticklabels({'1', '2', '3', '4', '5', '6', '7','8','9'})
ylabel('Rating')
subplot(1,2,2)
hold on; grid on;
set(gca, 'YGrid', 'on', 'XGrid', 'off')
The new order:
boxchart(3 * ones(1, length(s1)), s1, ...
'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 1), ...
'BoxFaceColor', ColorOrder(:, 1));
boxchart(2 * ones(1, length(s2)), s2, ...
'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 2), ...
'BoxFaceColor', ColorOrder(:, 2));
boxchart(ones(1, length(s3)), s3, ...
'LineWidth', 1.0, ...
'BoxEdgeColor', ColorOrder(:, 3), ...
'BoxFaceColor', ColorOrder(:, 3));
scatter(3,mean(Competence{2:15,2}),"+")
scatter(2,mean(Competence{2:16,2}),"+")
scatter(1,mean(Competence{2:15,2}),"+")
xticklabels({'No Tag', 'Hardcoded', 'Adaptive'})
This stuff doesn't change:
%% Final axes labels and options
title('Competence - New Order');
xticks(1:3)
xtickangle(45)
ylim([0 9])
yticks(1:9)
yticklabels({'1', '2', '3', '4', '5', '6', '7','8','9'})
ylabel('Rating')
1 comentario
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
