10 views (last 30 days)
Show older comments
Ayan on 26 Jun 2023
Commented: Voss on 15 Aug 2023
Open in MATLAB Online
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 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
Answers (1)
Voss on 2 Jul 2023
Open in MATLAB Online
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 Comment Show -1 older commentsHide -1 older comments
Show -1 older commentsHide -1 older comments
Voss on 15 Aug 2023
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/1988233-how-to-switch-order-of-boc-plots#comment_2850667
@Ayan: Did this answer work for you?
Sign in to comment.
Sign in to answer this question.
See Also
Categories
MATLABGraphics2-D and 3-D PlotsData Distribution Plots
Find more on Data Distribution Plots in Help Center and File Exchange
Tags
- boxchart
- matlab
- graph
- boxplot
- code
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office