Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: "overlaying" Stacked bar charts


From   Devra Golbe <[email protected]>
To   [email protected]
Subject   Re: st: RE: "overlaying" Stacked bar charts
Date   Thu, 18 Feb 2010 22:15:08 -0500

Thanks, Nick! Rearranging the data was key. I couldn't figure it out using -reshape- or -stack-, but the code below gets me what I want.

Devra

**************************
webuse citytemp, clear
collapse (mean) heat cool tempja tempju, by(region)
expandcl 2, cluster(region) gener(reg2)
forvalues  n = 1(2)7 {
   replace tempjan=. if reg2==`n'
   replace tempjuly=. if reg2==`n'
} forvalues n = 2(2)8 {
   replace heatdd=. if reg2==`n'
   replace cooldd=. if reg2==`n'
} label define reglbl 1 "NE" 2 "NE" 3 "N Central" 4 "N Central" 5 "South" 6 "South" 7 "West" 8 "West" label values reg2 reglbl graph bar tempjan tempjuly heatdd cooldd, over(reg2) stack ************************

on 2/17/2010 2:06 PM Nick Cox said:
-graph bar- does not permit overlay. That is a -twoway- concept. That
you know.
If you attempted to translate -graph bar- into an equivalent -twoway-
statement, you would need to do more work. For example, stacking bars
calls for -twoway rbar- rather than -twoway bar- and you still need to
do more work to specify the cumulated coordinates. And -twoway bar- does
not permit -over()-, as indicated.
I'd imagine you're better off staying with -graph bar-. But if I
understand you correctly you'd need to -reshape- or -stack- your data so
that you could then call -graph bar- with two separate -over()- options.


Nick [email protected]
Devra Golbe

Is there a way to "overlay" stacked bar charts? That is, using the citytemp data I can go

webuse citytemp
graph bar tempjan tempjuly, over(region) stack
graph bar  heatdd cooldd, over(region) stack

and get two separate graphs each over region. What I would like is one graph, with the temp bar for each region paired with the corresponding degree-day bar. I guessed the code would be something like the following pseudo-code, which results in an error:

twoway (bar tempjan tempjuly ) (bar  heatdd cooldd ), over(region) stack
option over() not allowed
r(198);


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index