adding individual points using scatter in a grouped bar graphs
Afficher commentaires plus anciens
Hi,
I managed to plot a grouped bar graph and error bar using MATLAB forum but I am lost to add individual points in each bar graph.
I found that I can use scatter to add individual data points but I failed. Could anyone help? Thanks.
S1 = [41 55];
S2 = [34 26];
P1 = [64 55 38 41 45 47];
P2 = [90 34 51 54 65 52];
mpi1 = [mean(S1) mean(P1)];
mpi2 = [mean(S2) mean(P2)];
mpi3 = [NaN mean(P3)];
all = [mpi1; mpi2];
S1_err = std(S1,'omitnan')/sqrt(size(S1,2));
Saline2_err = std(S2,'omitnan')/sqrt(size(S2,2));
PFF1_err = std(P1,'omitnan')/sqrt(size(P1,2));
PFF2_err = std(P2,'omitnan')/sqrt(size(P2,2));
mpi1_err = [S1_err P1_err];
mpi2_err = [S2_err P2_err];
all_err = [mpi1_err; mpi2_err];
b = bar(all, 'grouped');
hold on
% Calculate the number of groups and number of bars in each group
[ngroups,nbars] = size(all);
% Get the x coordinate of the bars
x = nan(nbars, ngroups);
for i = 1:nbars
x(i,:) = b(i).XEndPoints;
end
% Plot the errorbars
errorbar(x',all,all_err,'k','LineStyle','none','LineWidth',2,'Color',[0 0 0],'CapSize',12);
hold on
b(1).FaceColor = 'flat';
b(1).CData(1,:) = [0.7 0.7 0.7];
b(2).FaceColor = 'flat';
b(2).CData(1,:) = [1 0 0];
b(1).CData(2,:) = [0.7 0.7 0.7];
b(2).CData(2,:) = [1 0 0];
alpha(.5)
ca = categorical({'1mpi','2mpi','3mpi'});
ca = reordercats(ca,{'1mpi','2mpi','3mpi'});
set(gca,'xticklabel',ca)
legend('PFF','Saline')
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Discrete Data Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
