Stacked graph

For questions and discussion related to graphs, reports, and other output, including issues related to presenting or publishing results.
viking76
Posts: 13
Joined: Wed Jun 12, 2013 5:40 am

Stacked graph

Unread post by viking76 »

Dear RATS users,

I need to create a stacked graph. I noticed in the guide that the STACKED option is only useful with a set of non-negative values. However, the value of my variables is both positive and negative. In fact, the graphs generated are quite strange. Does anybody know whether there is a way to get a stacked graph also for negative values? The solution, at the moment, is to save the output on an xls file and generate the stacked graph in Excel, which allows me to generate stacked bar graphs also with negative values. Thanks a lot

Best

Adrian
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Stacked graph

Unread post by TomDoan »

How do you want that to work? Positive numbers stack away from zero up and negative ones stack away from zero down?
viking76
Posts: 13
Joined: Wed Jun 12, 2013 5:40 am

Re: Stacked graph

Unread post by viking76 »

exactly.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Stacked graph

Unread post by TomDoan »

If the series are consistently positive and consistently negative, this will do it:

Code: Select all

all 100
set pos1 = %rangamma(3.0)
set pos2 = %rangamma(3.0)
set neg1 = -%rangamma(3.0)
set neg2 = -%rangamma(3.0)
graph(style=stacked,overlay=stacked,ovcount=2,ovsamescale) 4
# pos1
# pos2
# neg1
# neg2
viking76
Posts: 13
Joined: Wed Jun 12, 2013 5:40 am

Re: Stacked graph

Unread post by viking76 »

Unfortunately the series are not consistently positive and consistently negative.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Stacked graph

Unread post by TomDoan »

See whether this comes close enough

Code: Select all

all 10
dec vect[series] x(4)
do i=1,4
   set x(i) = %ran(1.0)
end do i
dec vect[series] pos(4) neg(4)
do i=1,4
   set pos(i) = %max(0.0,x(i))
   set neg(i) = %min(0.0,x(i))
end do i
graph(style=stacked,overlay=stacked,ovcount=4,ovsamescale) 8
# pos(1)
# pos(2)
# pos(3)
# pos(4)
# neg(1) / 1
# neg(2) / 2
# neg(3) / 3
# neg(4) / 4
viking76
Posts: 13
Joined: Wed Jun 12, 2013 5:40 am

Re: Stacked graph

Unread post by viking76 »

It works fine with your example, but not with my data. I think I need to fix some further problems present in my code. Thanks a lot Tom! Your code is really what I needed.

Adrian
PTillmann-436
Posts: 20
Joined: Mon Dec 03, 2012 11:51 pm

Re: Stacked graph

Unread post by PTillmann-436 »

Dear Tom,

Can I plot a series as a line on top of stacked bars when the series are not consistently positive and negative?

Thanks for your help

Peter
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Stacked graph

Unread post by TomDoan »

I'm not sure I understand what "line on top of stacked bars" means. With version 9, STYLE=STACKED will handle a mix of positive and negative series as described above in the thread (positive values stacked up starting at zero, negative ones stacked down also from zero). If you want a line as well, you can do OVERLAY=LINE for the extra series.
Post Reply