I have made a clustered stack bar chart using Plot Groups of Stacked Bars by Evan on file exchange: http://www.mathworks.co.uk/matlabcentral/fileexchange/32884-plot-groups-of-stacked-bars/content/plotBarStackGroups.m
My data is in a 25x3x2 matrix. I currently have labels for the clusters (the 25 categories), and have used
to label the two variables within each bar.
I am missing labels for the individual bars (the 3 bars per cluster). Is there a way to have x labels for both the individual bars and the cluster, like the "A cluster-of-stacked-bars graph" shown on the webpage http://www.burningcutlery.com/derek/bargraph/?
No products are associated with this question.
Here is simple tweak to plotBarStackGroups.m that will allow you to label every single bar from left to right.
Just before the for loop, insert
xtick = ;
Just before the end of the for loop, insert
xtick = [xtick; groupDrawPos(:)];
And then, after the hold off insert
set(gca,'XTickMode','manual'); xts = sort(xtick); set(gca,'XTickLabelMode','manual','XTick',xts,'XTickLabel',groupLabels); end
and delete what else is there.
Now you should be able to call it as before, but now the second parameter needs to be a cell array with a string containing the label of every bar, from left to right. Nice feature though: If there are less elements in the cell array than bars, then Matlab cycles through. Example:
D=rand(25,3,2); % Make some Data C = mat2cell(char(randi(25,[25*3 1])+65),ones(25*3,1)); % and some labels plotBarStackGroups(D,C); % plot with a label for every bar plotBarStackGroups(D,C(1:3)); % that happens if you supply only 3 labels
You'll note that I used single-character labels. As soon as they get bigger it'll get very messy. And unfortunately, there is no easy way to rotate TickLabels in Matlab, you'll have to resort to the FEX there.
Also, there are now no more group labels, since those are only going to be less, you can maybe fix them there using text().
A third option would be to leave plotBarStackGroups as is and instead add labels on top of each bar, again using text. If you feel you need to do that let us know here, I'll try and help you with it.