How to create a mean bar for individual groups?

2 views (last 30 days)
I have a scatter plot x-axis is has two points - smoker and non-smoker y-axis is my variable of choice.
I am wondering how to create a mean bar for smoker and non smoker groups (something similar to setting Tools->Data Statistics where I would pick Y-mean) In this case however I dont need a unified mean across two points, I need individual mean for each point.
You help is greatly appreciated!

Answers (1)

Matt Tearle
Matt Tearle on 23 May 2011
Can you clarify what you mean by "x-axis is has two points - smoker and non-smoker". For a scatter plot you need equal-sized x and y vectors. Do you have a separate vector that identifies smoker/nonsmoker? If so, why not split into two groups and plot together on the same axes:
% identify smokers
idx = strcmp('Y',smoker);
% make plot
plot(x(idx),y(idx),'o',x(~idx),y(~idx),'o')
meansmoke = mean(y(idx));
meannonsm = mean(y(~idx));
line(xlim,meansmoke*[1,1],'color',[0 0 1])
line(xlim,meannonsm*[1,1],'color',[0 0.5 0])
(Here I'm assuming you have a char array smoker that is either 'Y' or 'N')

Community Treasure Hunt

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

Start Hunting!