Errorbar on Box and Whisker Plot

조회 수: 28 (최근 30일)
Stuti Agrawal
Stuti Agrawal 2021년 7월 20일
댓글: Ive J 2021년 7월 23일
I am confused on how I can add error bars to my box and whisker plot:

답변 (1개)

Ive J
Ive J 2021년 7월 22일
편집: Ive J 2021년 7월 23일
If you want error bars on the same box plots, you can use something like this:
tab = table(randi([1, 50], 20, 1), repmat([1; 2], 10, 1), 'VariableNames', {'value', 'group'}); % sample data with 2 groups: 1 and 2
hold on
boxchart(tab.group, tab.value)
% update the boxchart with data points + errorbars
for i = 1:2
y = tab.value(tab.group == i);
x = ones(sum(tab.group == i), 1).*i;
plot(x, y, 'o', 'MarkerFaceColor', 'r') % first show data points
errorbar(i, mean(y), mean(y)+std(y), 'Marker', 'o', 'MarkerFaceColor', 'k', 'Color', 'k') % then show error around the mean value only
end
  댓글 수: 2
Stuti Agrawal
Stuti Agrawal 2021년 7월 23일
Thank you! I guess what I am trying to achieve is adding an erorr bar to a single point in that box plot (two in total). So one on the green dot in the first plot and one on the red dot in the second plot. I also would like for it to be vertical rather than horizontal since the values i am comparing are against the y-axis.
Ive J
Ive J 2021년 7월 23일
So take a look at my edited snippet. Error in this case is only shown around the mean.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Errorbars에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by