How to create a mean bar for individual groups?
이전 댓글 표시
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!
답변 (1개)
Matt Tearle
2011년 5월 23일
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')
카테고리
도움말 센터 및 File Exchange에서 Scatter Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!