Statistics: column scatter plot / 2D-dot plot + mean + std dev
11 次查看(过去 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!!!
0 个评论
回答(2 个)
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!