connecting bargraph data points with a line

12 vues (au cours des 30 derniers jours)
Seble Zewdie
Seble Zewdie le 13 Juin 2019
Commenté : Seble Zewdie le 13 Juin 2019
Hi all, I have been sratching my head for a couple of days to connect each of the data points I plotted on a bar graph. I have a repeated measures design where I would like to make a before-after comparison. In the currect graph I succeed in showing the presence or lack of group differences. But I would also like to show how each individual subject responded to the manipulation. So I would like to connect the subject 1 before data point to the subject 1 after data point. Any idea how I can achieve this? Below is my code. Thanks in advance for your advice.
% data1_nor_mean_band (band,:) & data2_nor_mean_band (band,:) are a 1x8 vectors
% START PLOTTING
F=figure;
hs= superbar(a,'E',asem,'ErrorbarStyle', 'T');%barwitherr(astd,a);%superbar(a,'E',astd,'ErrorbarStyle', 'T');
hold on
ax=gca;
ax_detail=get(gca);
ahandle=get(gca,'Children');
Line1=ahandle(1,1);
Line1.Color= 'k';
Line2=ahandle(2,1);
Line2.Color=C(2,:); %[0 0 0];
Line2.Color='k'; %[0 0 0];
Bar1=ahandle(3,1);
Bar1.EdgeColor= 'k';% [ 0.90 0.55 0.55];%[1 0 0];
Bar1.FaceColor= 'none';%[1 0 0]
Bar2=ahandle(4,1);
Bar2.EdgeColor= 'k';% [0.62 0.76 0.84];% [0 0 0];
Bar2.FaceColor= 'none';%[1 0 0];
ax.XLim=[0.4000 2.6000];
Bar1.BarWidth=0.8;
Bar2.BarWidth=0.8;
set(gca,'FontSize',20,'FontName','Arial')
set(gca,'Box','off')
set(gca,'LineWidth',2); % default 0.5
set(gca, 'XTick',[1 2 ])
set(gca,'XTickLabel',{labels{1,1},labels{2,1}})
title(sprintf('%s %s',strain,structure),'FontWeight','normal','FontSize',20,'FontName','Arial')%title(sprintf('%s:%s, %s',strain,structure,period),'FontWeight','normal')
ylabel(sprintf('z-normalised power\n %s (%d-%dHz)',fband_name{1,band},fband{band}(1,1),fband{band}(1,2)),'FontSize',20,'FontName','Arial');
% PLOT DATA POINTS ON BARS
ax1=get(Bar1,'XData'); % get position of Bar
ax2=get(Bar2,'XData'); % get position of Bar
for i=1:length(data2_nor_mean_band)
bp2(i,1)=plot(ax1(1,1) - (0.01*i),data2_nor_mean_band(band,i),'ro','Color','r','MarkerSize',6,'MarkerFaceColor','r');%C(1,:)) ;
% ax1(1,1) position of the bar graph desired
% added to give the scatterplot a jitter
hold on
end
for i=1:length(data1_nor_mean_band)
bp1(i,1)=plot(ax2(1,1)- (0.01*i),data1_nor_mean_band(band,i),'ko','Color','b','MarkerSize',6,'MarkerFaceColor','b');%C(2,:));
hold on
end
% plotting sigasterics
if expmeasure==1
if h1==0 & h2==0
pvalplot=text(1.1, max(Line1.YData)*1.2,sprintf('p = %0.3f',P),'FontName','Arial','FontSize',20);
else
pvalplot=text(1.1, max(Line1.YData)*1.2,sprintf('p = %0.3f',H),'FontName','Arial','FontSize',20);
end
end
if expmeasure==2
if h1==0 & h2==0
pvalplot=text(1.1, max(Line1.YData)*1.2,sprintf('p = %0.3f',P),'FontName','Arial','FontSize',20);
else
pvalplot=text(1.1, max(Line1.YData)*1.2,sprintf('p = %0.3f',P),'FontName','Arial','FontSize',20);
end
end
  1 commentaire
Seble Zewdie
Seble Zewdie le 13 Juin 2019
Ah! I think I suceeded. Thanks for reading anyway. Below is my solution:
x = [get(bp1(1,1),'XData') get(bp2(1,1),'XData')];
y = [get(bp1(1,1),'YData') get(bp2(1,1),'YData')];
line(x,y,'Color','red','LineStyle','--')

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by