Display mean of data on a boxchart
Show older comments
I need to show the mean of each box plot on the figure. here is the code to generate my box plot:
x = 1:numel(data);
colors = rand(numel(data), 3);
figure();
ax = axes();
hold(ax);
for i=1:numel(data)
boxchart(x(i)*ones(size(data{i})), data{i},'MarkerStyle','none', ...
'BoxFaceColor', colors(i,:), ...
'LineWidth', 0.5, ...
'WhiskerLineStyle', '-')
end
set(gca,'xtick',[])
When I had just one boxplot I simply used this line:
hold on
plot(mean(x), '*')
But here when I use it in the code:
x = 1:numel(data);
colors = rand(numel(data), 3);
figure();
ax = axes();
hold(ax);
for i=1:numel(data)
boxchart(x(i)*ones(size(data{i})), data{i},'MarkerStyle','none', ...
'BoxFaceColor', colors(i,:), ...
'LineWidth', 0.5, ...
'WhiskerLineStyle', '-')
plot(mean(data{i}), '*') %%%%%%%%%%<<<<<<<<<<<<< HERE
end
set(gca,'xtick',[])
It shows all mean values on the first boxplot only, meanwhile I need to have one * as a mean value for each boxplot.

Best Regards
Accepted Answer
More Answers (0)
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!