Statistics: column scatter plot / 2D-dot plot + mean + std dev

조회 수: 11 (최근 30일)
Monica
Monica 2015년 8월 30일
답변: Star Strider 2015년 8월 30일
Hi! Basically, a picture is worth 1000 words. This is what I would like to do:
I have 3 different groups and I want to do the scatter plot of, let's say, their blood pressure.
1 - I want to do a scatter plot with the groups on X axis, and the values of the blood pressure on the Y. Just this, no other variable to compare.
2 - And how can I also plot the mean and standard deviation together with the individual data points, if possible? Or only for the group, as in the image.
(I will repeat this process for other variables, so I can see their behaviour and know which variables could distinguish one group from another - if you have any other suggestion other than the scatterplot, I also appreciate. But the scatter plot I would like to do first)
Thank you!!!

답변 (2개)

Star Strider
Star Strider 2015년 8월 30일
From a statistical perspective, the boxplot is correct (plots medians and percentiles) but for your application, this should work:
data = bsxfun(@times, rand(5,3), [50 150 100]); % Create Data
dmean = mean(data); % Mean
dci = std(data)*tinv(0.975,size(data,1)-1); % Confidence Intervals
xt = [1:3]; % X-Ticks
xtd = repmat(xt, size(data,1), 1); % X-Ticks For Data
sb = [xt'-ones(size(data,2),1)*0.1, xt'+ones(size(data,2),1)*0.1]; % Short Bar X
lb = [xt'-ones(size(data,2),1)*0.2, xt'+ones(size(data,2),1)*0.2]; % Long Bar X
figure(1)
plot(xt, data, '+')
hold on
for k1 = 1:size(data,2)
plot(lb(k1,:), [1 1]*dmean(k1), sb(k1,:), [1 1]*(dmean(k1)-dci(k1)), sb(k1,:), [1 1]*(dmean(k1)+dci(k1)), '-k')
end
hold off
set(gca, 'XTick', xt, 'XTickLabel', {'Left','Middle','Right'})
xlabel('Group')
ylabel('Velocity (Furlongs/Fortnight)')
I plotted ±95% confidence intervals, but if you want to plot something else, just change the ‘dci’ assignment. The rest of the code will adapt automatically.

michael scheinfeild
michael scheinfeild 2015년 8월 30일
gscatter(x,y,group)
this will plot each group in different color
  댓글 수: 1
Monica
Monica 2015년 8월 30일
Thank you, but that is not what I want to do. I want to see how one variable is behaving in the 2+ groups, separately. So, if this command worked, I would use scatter(group, y).

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

Community Treasure Hunt

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

Start Hunting!

Translated by