2013-04-28 96 views
4

我有x = rand(1000,6); Y =蘭特(1000,6); d(:,1:2:12)= X; d(:,2:2:12)= Y;分組boxplot matlab

我想繪製一個分組boxplot其中x(:,i)和y(:,i)是分組的盒形圖(或因子對)。但似乎無法解決如何指定分組。

這樣:

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

但它看起來有點凌亂,我如何才能對箱線圖之間的差距較大?

回答

3

你需要一個雙組變量:

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

居中標籤是相當不切實際和nightmerish。