MATLAB Answers

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

83 views (last 30 days)
Monica
Monica on 30 Aug 2015
Answered: Star Strider on 30 Aug 2015
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 Comments

Sign in to comment.

Answers (2)

Star Strider
Star Strider on 30 Aug 2015
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 Comments

Sign in to comment.


michael scheinfeild
michael scheinfeild on 30 Aug 2015
gscatter(x,y,group)
this will plot each group in different color

  1 Comment

Monica
Monica on 30 Aug 2015
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).

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!