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: Margins not aligned for stacked hbar grc1leg


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Margins not aligned for stacked hbar grc1leg
Date   Thu, 14 Mar 2013 15:46:33 +0000

I am puzzled by these comments.

You produced 6 graphs and then combined them with -grc1leg- (Vince
Wiggins). That's what I meant by producing graphs separately. You can
get what you seemed to want with one command and without using
-grc1leg-.

(Also, although you did not ask this, it's my view that you can get a
much cleaner and more effective graph with a different approach.)

Nick

On Thu, Mar 14, 2013 at 3:40 PM, kavita sardana
<[email protected]> wrote:
> Thanks Nick
>
> Graphs are not produced separately, they are produced as one graph.
> However, the last graph(a2.gph) is not aligned with the other 5
> graphs(a.gph, a1a.gph, a1b.gph, a1c.gph, a1d.gph) on the left margin.
>
> Other than that it the program is running fine.
>
> On Thu, Mar 14, 2013 at 7:24 PM, Nick Cox <[email protected]> wrote:
>> Comments on various levels:
>>
>> 1. This won't run without a fix: the last category of -q- is defined
>> as "above 65" but the last separate graph is for "above65" and there
>> are no such observations. That is, a space should be inserted to fix.
>>
>> 2. -grc1leg- is not explained as being user-written, and as downloaded
>> from where, and the code won't run unless it is installed.
>>
>> 3. I don't see why the graphs are being produced separately when they
>> can be produced as one. You just need -over(q)- and not to restrict
>> graphs to each age category.
>>
>> 4. However, stacking and showing the numerical values just doesn't
>> work well here when several of your percents are zero or otherwise
>> very small. There just isn't enough space to put the values for small
>> percents anywhere!
>>
>> 5. I suggest something different, in essence a table of bars. My
>> -tabplot- (SSC) is one possibility, but here's an approach with
>> official commands.
>>
>> First, you need a different data structure.
>>
>> reshape long a, i(q) j(answer)
>> label def answer 1 "No Change" 2 "Better" 3 "Worse" 4 "No direct
>> experience" 5 "Don't know"
>> label val answer answer
>> encode q, gen(age)
>> gen a2 = round(a,1)
>>
>> Then I produce a table of bars.
>>
>> twoway bar a age, horizontal by(answer, row(1) compact legend(off)
>> note(""))  barw(0.7) ///
>> ysc(reverse) xla(none) xsc(r(. 80)) yla(1/6, nogrid valuelabel ang(h)
>> tlength(0)) ytitle("") ///
>> || scatter age a, ms(none) mla(a2) xtitle("")
>>
>> Suggestions here:
>>
>> If you show the numbers, you don't need the numerical scale too.
>>
>> If you show the numbers, you don't need 2 decimal places.  Round first.
>>
>> I've not disturbed your ordering, beyond correcting punctuation, but
>> I'd guess that "No change" belongs between "Better" and "Worse".
>>
>> You need the Graph Editor too to edit "No direct experience" to two lines.
>>
>> There's more in the same vein at
>>
>> SJ-8-2  gr0034  . . . . . . . . . .  Speaking Stata: Between tables and graphs
>>         (help labmask, seqvar if installed) . . . . . . . . . . . .  N. J. Cox
>>         Q2/08   SJ 8(2):269--289
>>         outlines techniques for producing table-like graphs
>>
>> and a .pdf is accessible at
>> http://www.stata-journal.com/sjpdf.html?articlenum=gr0034
>>
>> Nick
>>
>> On Thu, Mar 14, 2013 at 8:46 AM, kavita sardana
>> <[email protected]> wrote:
>>> I am combining 5 stacked hbar graphs. For the last hbar graph, for age
>>> group "above 65", margins are not aligned. Will appreciate any help on
>>> this.
>>>
>>>
>>> clear all
>>>
>>> input str25 q a1 a2 a3 a4 a5
>>>
>>> "18-24" 14.29 52.63 26.32 6.77 0.00
>>>
>>> "25-34" 9.04 65.96 23.40 1.60 0.00
>>>
>>> "35-44" 10.67 54.49 33.15 0.56 1.12
>>>
>>> "45-54" 9.01 67.57 22.52 0.90 0.00
>>>
>>> "55-64" 10.29 61.76 23.53 4.41 0.00
>>>
>>> "above 65" 0.00 69.23 30.77 0.00 0.00
>>>
>>> end
>>>
>>> graph hbar a1-a5 if q=="18-24", percent over(q, label (labsize(tiny))
>>> gap(20)) blabel(bar, format(%3.2f) position(center)) ytitle("Age") ///
>>>
>>> stack legend(off) yscale(off) yline(20 40 60 80 ,lwidth(0.25) lcolor(black)) ///
>>>
>>> saving(a1, replace)yscale(off) plotregion(margin( b+1 t+1)) outergap(50)
>>>
>>>
>>>
>>> graph hbar a1-a5 if q=="25-34", percent over(q, label (labsize(tiny))
>>> gap(20)) blabel(bar, format(%3.2f) position(center)) ytitle("Age") ///
>>>
>>> stack legend(off) yscale(off) yline(20 40 60 80 ,lwidth(0.25)lcolor(black)) ///
>>>
>>> saving(a1a, replace)yscale(off) plotregion(margin( b+1 t+1)) outergap(50)
>>>
>>>
>>>
>>> graph hbar a1-a5 if q=="35-44", percent over(q, label (labsize(tiny))
>>> gap(20)) blabel(bar, format(%3.2f) position(center)) ytitle("Age") ///
>>>
>>> stack legend(off) yscale(off) yline(20 40 60 80 ,lwidth(0.25) lcolor(black)) ///
>>>
>>> saving(a1b, replace)yscale(off) plotregion(margin( b+1 t+1)) outergap(50)
>>>
>>>
>>>
>>> graph hbar a1-a5 if q=="45-54", percent over(q, label (labsize(tiny))
>>> gap(20)) blabel(bar, format(%3.2f) position(center)) ytitle("Age") ///
>>>
>>> stack legend(off) yscale(off) yline(20 40 60 80 ,lwidth(0.25)lcolor(black)) ///
>>>
>>> saving(a1c, replace)yscale(off) plotregion(margin( b+1 t+1)) outergap(50)
>>>
>>>
>>>
>>> graph hbar a1-a5 if q=="55-64", percent over(q, label (labsize(tiny))
>>> gap(20)) blabel(bar, format(%3.2f) position(center)) ytitle("Age") ///
>>>
>>> stack legend(off) yscale(off) yline(20 40 60 80 ,lwidth(0.25) lcolor(black)) ///
>>>
>>> saving(a1d, replace)yscale(off) plotregion(margin( b+1 t+1)) outergap(50)
>>>
>>>
>>>
>>> graph hbar a1-a5 if q=="above65", percent over(q,label (labsize(tiny))
>>> gap(40)) blabel(bar, format(%3.2f) position(center)) ytitle("Age") ///
>>>
>>> stack legend(span rows(1) label(1 "No Change") label(2 "Better") ///
>>>
>>> label(3 "Worse") label(4 "No direct experience") label(5 "Dont know") ///
>>>
>>> size(tiny)) ///
>>>
>>> yline(20 40 60 80 ,lwidth(0.25 ) lcolor(black)) saving(a2, replace)
>>>
>>> grc1leg a1.gph a1a.gph a1b.gph a1c.gph a1d.gph a2.gph, cols(1) ///
>>>
>>> imargin(0 0 0 0) xcommon legendfrom(a2.gph)
>>>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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