Page 1 of 1
Stacked graph
Posted: Wed Jun 12, 2013 8:02 am
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
Re: Stacked graph
Posted: Wed Jun 12, 2013 10:31 am
by TomDoan
How do you want that to work? Positive numbers stack away from zero up and negative ones stack away from zero down?
Re: Stacked graph
Posted: Wed Jun 12, 2013 10:34 am
by viking76
exactly.
Re: Stacked graph
Posted: Wed Jun 12, 2013 11:12 am
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
Re: Stacked graph
Posted: Wed Jun 12, 2013 11:43 am
by viking76
Unfortunately the series are not consistently positive and consistently negative.
Re: Stacked graph
Posted: Wed Jun 12, 2013 12:33 pm
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
Re: Stacked graph
Posted: Mon Jun 17, 2013 3:28 am
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
Re: Stacked graph
Posted: Sat Dec 12, 2015 3:40 pm
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
Re: Stacked graph
Posted: Sun Dec 13, 2015 7:58 pm
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.