Stacked bar plot for individual object accumulation in a date series

1 visualización (últimos 30 días)
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.

Respuestas (4)

Laura Proctor
Laura Proctor el 17 de Mzo. de 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.
  1 comentario
fabius
fabius el 18 de Mzo. de 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.

Iniciar sesión para comentar.


the cyclist
the cyclist el 17 de Mzo. de 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 comentarios
fabius
fabius el 18 de Mzo. de 2011
Tanks! is what I looked for.
if you have some suggestion for a better rappresentation than bar chart, please, tell me.
fabius
fabius el 18 de Mzo. de 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... :(

Iniciar sesión para comentar.


fabius
fabius el 18 de Mzo. de 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
the cyclist el 20 de Mzo. de 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.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by