Grouping boxplot in matlab

Here an example from The example is about on how to create a boxplot for multiple group of variables. The example as follows:

x=rand(1000,6); %variable x
y=rand(1000,6); %variable y
D(:,1:2:12)=x; %rearrange x into d.
D(:,2:2:12)=y; %rearrange y into d

% first column of D, will fill with column of x, then second... 
% column of D will fill with 1st column of y. then the sequent... 
% will follow.


figure('color',[1,1,1]); %create a blank graph
boxplot(D,'factorgap',10,'color','rk') %make a box plot on those blank graph
axis([0 25 -1 5]) %not compulsory:rearrange back axis 

set(gca,'xtick',1.8:4.3:50) %put xtick to x-axis
set(gca,'ytick',0:10) %put tick to y-axis
set(gca,'xticklabel',{'Direct care','Housekeeping','Mealtimes','Medication','Miscellaneous','Personal care'}) %label to each x-axis

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

Be the first to comment

Leave a Reply

Your email address will not be published.