HCAI
HCAI

Reputation: 2263

Grouping boxplot matlab

I have x=rand(1000,6); y=rand(1000,6); D(:,1:2:12)=x; D(:,2:2:12)=y;

I would like to plot a grouped boxplot where x(:,i) and y(:,i) are grouped boxplots (or factor pairs). But can't seem to work out how to specify the groupings.

Thus:

figure('color',[1,1,1]);
boxplot(D,'factorgap',10,'color','rk')
axis([0 25 -1 5])

set(gca,'xtick',1.8:4.3:50)
set(gca,'ytick',0:10)
set(gca,'xticklabel',{'Direct care','Housekeeping','Mealtimes','Medication','Miscellaneous','Personal care'})

ylabel('Normalised Y');
 legend(findobj(gca,'Tag','Box'),'HBN04-01 multibed','YAB single ')

enter image description here

But it looks a bit untidy, how do I get the gaps between pairs of boxplots larger?

Upvotes: 4

Views: 7500

Answers (1)

Oleg
Oleg

Reputation: 10676

You need a double grouping variable:

boxplot(D, {reshape(repmat('A':'F',2,1),12,1) repmat((1:2)',6,1)} ,'factorgap',10,'color','rk')

Centering the labels is quite impractical and nightmerish.

Upvotes: 3

Related Questions