Boxchart(箱​ひげ図)におけるペア​間の幅を調節したい Adjust widths between each boxchart pairs

3 views (last 30 days)
現在、画像のような箱ひげ図を作成しています。各ペア(赤と青)の幅をなくしたいのですが、どうすればよいでしょうか。factorgapという関数を用いたらできそうですが...。以下、コードです。よろしくお願いします。
tbl1 = readtable('file.csv');
ProtocolOrder = {'A','B','C','D','E'};%x軸の順を定義
boxchart(tbl1.Type,tbl1.RMS,'GroupByColor',tbl1.Side)%BoxChartの作成
b1 = boxchart(tbl1.Type,tbl1.RMS,'GroupByColor',tbl1.Side) %BoxChart格納
~以下書式に関しては省略~
yticks([0 100 200 300 400]);%y軸間隔を定義
b1(1).XTickLabel = [];x軸を空白
b1(2).XTickLabel = [];
legend
  6 Comments
Raki Kawama
Raki Kawama on 21 Dec 2021
dat = readtable('File.csv')
x1 = dat(dat.Protocol==1,:);
x1_D = x1(x1.Dominant==1,:);
x1_N = x1(x1.Dominant==2,:);
x2 = dat(dat.Protocol==2,:);
x2_D = x2(x2.Dominant==1,:);
x2_N = x2(x2.Dominant==2,:);
x3 = dat(dat.Protocol==3,:);
x3_D = x3(x3.Dominant==1,:);
x3_N = x3(x3.Dominant==2,:);
x4 = dat(dat.Protocol==4,:);
x4_D = x4(x4.Dominant==1,:);
x4_N = x4(x4.Dominant==2,:);
x5 = dat(dat.Protocol==5,:);
x5_D = x5(x5.Dominant==1,:);
x5_N = x5(x5.Dominant==2,:);
X = [x1_D; x1_N; x2_D; x2_N;...
x3_D; x3_N; x4_D; x4_N; x5_D; x5_N];
% two group variables
g1 = X.Protocol;
g2 = X.Dominant;
% create box plot with extra spacing between the g1 boxes
boxplot(X.RMS, [g1 g2],'factorgap', 2,'Colors','k','FactorSeparator',[1,1],'width',0.6,'symbol','');
a = get(get(gca,'children'),'children');
t = get(a,'tag');
box1 = a([21 31 41 51 61 71 81]); % Difine of each box
box2 = a([23 33 43 53 63 73 83]);
box3 = a([25 35 45 55 65 75 85]);
box4 = a([27 37 47 57 67 77 87]);
box5 = a([29 39 49 59 69 79 89]);
box6 = a([22 32 42 52 62 72 82]);
box7 = a([24 34 44 54 64 74 84]);
box8 = a([26 36 46 56 66 76 86]);
box9 = a([28 38 48 58 68 78 88]);
box10 = a([30 40 50 60 70 80 90]);
set(box1, 'Color', [0.6784 0.6784 0.6784]) %Change box color
set(box2, 'Color', [0.6784 0.6784 0.6784])
set(box3, 'Color', [0.6784 0.6784 0.6784])
set(box4, 'Color', [0.6784 0.6784 0.6784])
set(box5, 'Color', [0.6784 0.6784 0.6784])
set(box6, 'Color', [0.1490 0.1490 0.1490])
set(box7, 'Color', [0.1490 0.1490 0.1490])
set(box8, 'Color', [0.1490 0.1490 0.1490])
set(box9, 'Color', [0.1490 0.1490 0.1490])
set(box10, 'Color', [0.1490 0.1490 0.1490])
set(box1,'LineWidth',1.25) % Change line width
set(box2,'LineWidth',1.25)
set(box3,'LineWidth',1.25)
set(box4,'LineWidth',1.25)
set(box5,'LineWidth',1.25)
set(box6,'LineWidth',1.25)
set(box7,'LineWidth',1.25)
set(box8,'LineWidth',1.25)
set(box9,'LineWidth',1.25)
set(box10,'LineWidth',1.25)
set(gca,'Fontsize',[12])
set(gca,'FontWeight','bold')
set(gca,'FontName','Times New Roman')
set(gca,'TickDir','out')
set(gca,'XTickLabel',{' '})
ylim([0 400]) %Change a range of y axis
yticks([0 100 200 300 400]);
Raki Kawama
Raki Kawama on 21 Dec 2021
こちらで添付のような図が完成されるかと思います。
デザインに関しては、BoxChartの方が最初からBoxも塗りつぶされており、少々手間が少ないかなと思いました。
まぁ、仰る通り同じ絵になればよいですが。

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!