Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

plotting two grouped stacked bar

1,272 views
Skip to first unread message

Lee Sander

unread,
Sep 17, 2010, 2:40:54 PM9/17/10
to
Hi,
I have 3 data on 4 patients (call them a,b,c,d) at 2 time points.
i.e.
time point 1
TP1=[
10 10 20
5 14 17
1 10 19
2 13 5]

and time point 2
TP2=[
15 3 5
10 11 2
4 2 10
5 10 10]

and a similar matrix at time point 2.
I can get a stacked plot (i.e. 3 values for each patient) by doing
bar(TP1,'stacked') and bar(TP2,'stacked') separately.
but I want to plot them together and grouped
i.e. I want to see how the each row changes from TP1 to TP2.
and would like each of the two stacked bars for each patient close
together i.e.

TP1a TP2a TP1b TP2b TP1c TP2c TP1d TP2d


Can someone please help
Lee

eykanal

unread,
Dec 15, 2010, 11:17:33 AM12/15/10
to
Quite a delayed answer, but just in case anyone else has this problem, you can easily solve this by using the "bar(x,Y)" form of the bar function. The "x" argument is a positioning vector, and you can use it to put the bars wherever you want. This works with stacked bar plots as well. Check out the "bar" documentation for more.

Elli

Constantine

unread,
Feb 8, 2011, 10:33:04 AM2/8/11
to
eykanal <eyk...@gmail.com> wrote in message <70fbeb35-1b24-4f0f...@glegroupsg2000goo.googlegroups.com>...

> Quite a delayed answer, but just in case anyone else has this problem, you can easily solve this by using the "bar(x,Y)" form of the bar function. The "x" argument is a positioning vector, and you can use it to put the bars wherever you want. This works with stacked bar plots as well. Check out the "bar" documentation for more.
>
> Elli

>This may be a very roundabout way...but adding to the method described above...
x1 coordinates: [0.5 1.5 2.5];
x2 coordinates: [1 2 3];
y1 = [10,20;10,5;30,10];
h1 = bar(x1,y1,'stacked') % this should make a stacked bar graph located at the x1 coordinates
set(gca,'nextplot','add') %add on to the current graph
y2 = [5,5;10,10;20,20];
h2 = bar(x2,y2) %this adds another set of bar graphs on the same plot next to it to make two %series with stacked bar graphs

%You can then control the properties of each bar graph using the handles h1 and h2 (like %face color)

0 new messages