# Stacked bar plot for individual object accumulation in a date series

7 views (last 30 days)
fabius on 17 Mar 2011
I would represent my data in a bar graphic.
Imagine this situation:
01/01/2009 - 'wake up' - 'breakfast' - 'work' - 'sleep'
02/01/2009 - 'wake up' - 'work' - 'sleep'
03/01/2009 - 'wake up' - 'pray' - 'dinner' - 'sleep' ...
I would be able to have a bar graph, like stack bar in which I can have the daily succession of this, not numeric values. I would have, for each day a multicolor bar that represent, for each color, different actions.

Laura Proctor on 17 Mar 2011
It seems like a bar chart may not be what you are looking for, but I envision the following code as a launching point for you:
x = [ 2 1 6 0 0 1
2 0 7 0 0 1
2 0 0 5 2 1 ];
bar(x,'stacked')
where the columns in x represent a different activity and each row represents a day. I ensured that the rows all equaled the same value so that each "day" has the same length.
fabius on 18 Mar 2011
Thank you,
I tried this way, but cyclist had a good suggestion with binary values. in this way I can do as you suggested me, but with equal ranges in bar chart.
If you have some suggestion for a better rappresentation than bar chart, I'll appreciate.
thank you a lot.

the cyclist on 17 Mar 2011
Here is a start on how you could do this. Each activity is encoded into a binary yes/no bar of equal length.
Each row of the array "b" corresponds to a day, and each column is a binary value of whether or not the activity occurred that day.
I expect that a bar chart is not the best way to display these data, but that is for you to decide.
activity = {'wake up','breakfast','work','pray','dinner','sleep'};
b = [1 1 1 0 0 1; ...
1 0 1 0 0 1; ...
1 0 0 1 1 1];
figure
bar(b,'stacked')
legend(activity)
##### 2 CommentsShowHide 1 older comment
fabius on 18 Mar 2011
I was too happy..
but there is an unsolved problem,
I used a wrong example, because in this case is due that first of all I must "wake up", in other way the rotation of actions is always the same.
I need a rappresentation also if I invert some action, in other way I need to rappresent different actions in different rotation to examine the order of actions in different days..
sorry... :(

fabius on 18 Mar 2011
I was too happy.. but there is an unsolved problem, I used a wrong example, because in this case is due that first of all I must "wake up", in other way the rotation of actions is always the same. I need a rappresentation also if I invert some action, in other way I need to rappresent different actions in different rotation to examine the order of actions in different days.. sorry... :(

the cyclist on 20 Mar 2011
In a stacked bar chart, the colors will always appear in the same order (unless they are absent altogether).
The only way I can think of to get what you want is to manually fill in rectangles according to the schedule, using the patch command. Here's a very simple example of using patches to paint rectangles on a set of axes:
figure
axis
patch([0 1 1 0],[0 0 1 1],'r');
patch([1 2 2 1],[0 0 1 1],'b');
patch([0 1 1 0],[1 1 2 2],'g')
See "help patch" for more details.