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: graph bar - how to add 'external' label above stacked bar chart


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: graph bar - how to add 'external' label above stacked bar chart
Date   Thu, 17 Feb 2011 00:22:41 +0000

This is in the spirit of Phil's first suggestion:

sysuse census, clear
graph bar (sum) marri div, over(region) stack

more

collapse (sum) marri div, by(region)
gen ratio = div / (marri + div)
gen sratio = string(ratio, "%4.3f")
gen marriPdiv = marria + div

twoway bar marria region, barw(0.6) base(0) ///
|| rbar marria marriPdiv region, barw(0.6) xla(1/4, noticks valuelabel) ///
|| scatter marriPdiv region, ms(none) mla(sratio) mlabpos(12)  ///
legend(order(1 "marriages" 2 "divorces")) ///
yla(0 4e5 "400"  8e5 "800" 12e5 "1200" , ang(h)) ytitle(thousands) ///
ysc(r(. 14e5))

Nick

On Thu, Feb 17, 2011 at 12:15 AM, Phil Clayton
<[email protected]> wrote:

> I'm sure others have better suggestions but 2 options include:
>
> 1. use -twoway bar- instead of -graph bar-, and scatter C against the group with
> invisible markers labelled with their value
>
> 2. draw the bar graph without the labels, then invoke the Graph Editor to add the
> labels manually (requires more programming):
>
> _gm_edit .graphname.plotregion1.barlabels[1].text.Arrpush C1 %
> _gm_edit .graphname.plotregion1.barlabels[2].text.Arrpush C2 %
> ...
> graph display graphname


> On Thu 17/02/11 10:40 , Vianney [email protected] sent:

>> I am trying to create a stacked bar chart that graphs 2 volumes (say
>> variables 'A' & 'B'), but that also includes a label on top of each
>> bar. This label, however, is neither variable `A' nor `B', but a third
>> piece of information, 'C'
>>
>> Specifically, it would appear that the option blabel() is not
>> appropriate here, as my variable 'C' is NOT:
>>
>> * the bar height
>> * the cumulative bar height
>> * the name of yvar
>> * the name of the first over() group
>>
>> > It's actually a percentage value that is in my
>> dataset, where C = (B/(A+B))> How would I modify the Stata command below to
>> add 'C' as a label on top of each stacked bar?
>> #delimit ;
>> graph bar (sum) A B, over(yearnum) over(country) stack
>> ;
>> #delimit cr
>>
*
*   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