Statalist


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

Re: st: AW: RE: Caption on a bar graph


From   Dorothy Bridges <dbstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: AW: RE: Caption on a bar graph
Date   Mon, 19 Oct 2009 16:49:10 -0400

Dear Nick:

Thanks for your help (and for your advice on how best to pose
questions; I will follow it in the future).  When I run this code:

clear
set obs 10
gen whatever = _n
forval i = 1/10 {
       gen foobar`i' = uniform()
}

#delimit;
graph bar foobar*, over(whatever, label(labsize(medium))) percentages stack
graphregion(fcolor(white) lcolor(white) margin(zero))
plotregion(fcolor(white) lcolor(white) ilcolor(white))
title("title",color(black) placement(west) justification(left) size(large))
caption("This is the problem I'm having", size(vsmall) placement(west)
justification(left))
legend(cols(1) span position(3) stack region(lcolor(white)) title(" ",
size(small))
order(10 9 8 7 6 5 4 3 2 1) rowgap(7) keygap(1)
label(1 "Agriculture") label(2 "Mining, Oil & Gas") label(3 "Construction")
label(4 "Wholesale" "& Retail Trade") label(5 "Financial Services")
label(6 "Other Services") label(7 "Public Administration")
label(8 "Utilities") label(9 "Transport" "& Communication")
label(10 "Manufacturing"))
xsize(7.5) ysize(4.1) ytitle("")
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%",
glwidth(thin) glcolor(black) angle(horizontal) labsize(medium))
;

the problem I referred to occurs.  This is precisely the code you so
kindly wrote for me below (I will do this myself next time).  I've
tried changing the margins, ring() option, adding a blank b2 title ...
nothing works.  What might be going wrong?

Thanks again,
Dorothy



On Mon, Oct 19, 2009 at 1:48 PM, Nick Cox <n.j.cox@durham.ac.uk> wrote:
> To emphasise the same idea:
>
> 1. We don't have your data.
>
> 2. Even Stata experts like Martin can find it difficult to see what's problematic in a bunch of code.
>
> 3. Thus our best chance is to work at a replica of your problem. It's easier if you set that up for us. If you want free help, as you do, it is better to make the question as easy as possible.
>
> I can see from your code that you have ten variables. I can't see how many categories of -year- you have. The following code sets up ten categories for ten years, and although the resulting graph is busy -- and alternatives spring to mind, but that is not the issue. But it does not show any overprinting. What's different about your real data?
>
> clear
> set obs 10
> gen whatever = _n
> forval i = 1/10 {
>        gen foobar`i' = uniform()
> }
>
> graph bar foobar*, over(whatever, label(labsize(medium))) percentages stack ///
> graphregion(fcolor(white) lcolor(white) margin(zero)) ///
> plotregion(fcolor(white) lcolor(white) ilcolor(white)) ///
> title("title",color(black) placement(west) justification(left) size(large)) ///
> caption("caption", size(vsmall) placement(west) justification(left)) ///
> legend(cols(1) span position(3) stack region(lcolor(white)) title(" ", size(small)) ///
> order(10 9 8 7 6 5 4 3 2 1) rowgap(7) keygap(1) ///
> label(1 "Agriculture") label(2 "Mining, Oil & Gas") label(3 "Construction") ///
> label(4 "Wholesale" "& Retail Trade") label(5 "Financial Services") ///
> label(6 "Other Services") label(7 "Public Administration") ///
> label(8 "Utilities") label(9 "Transport" "& Communication") ///
> label(10 "Manufacturing")) ///
> xsize(7.5) ysize(4.1) ytitle("") ///
> ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", ///
> glwidth(thin) glcolor(black) angle(horizontal) labsize(medium))
>
> Nick
> n.j.cox@durham.ac.uk
>
> Martin Weiss
>
> " I'd like to avoid using graph editor
> if possible, given that I'll likely have to reproduce this graph later
>                With different data."
>
> Have you tried the recorder in the graph editor?
>
> Dorothy Bridges
>
> Thanks for looking into this.  When I say "on top of," I mean that the
> text appears on the same line as the category axis labels ... that is,
> they overlap.  In Nick's example, it would be as if the "whatever"
> line ran into "domestic."   Like Martin, however, I can't create the
> problem using the auto dataset.  I'd like to avoid using graph editor
> if possible, given that I'll likely have to reproduce this graph later
> with different data.  Maybe there's something strange in my long graph
> code?  Thanks for your help ...
>
>
> On Mon, Oct 19, 2009 at 11:40 AM, Martin Weiss <martin.weiss1@gmx.de>
>
>> To echo Nick`s sentiment, I have now tried for some time to get Stata to
>> behave "irrationally" with the -caption-, and have not succeeded, in spite
>> of my honest attempts to reproduce the command provided by Dorothy as much
>> as possible. As a last resort, she could still drag the thing around in
> the
>> graph editor...
>
> Nick Cox
>
>> I don't understand "underneath (or on top of, I guess)".
>>
>> It is easier to address problems reproduced with datasets everyone can
>> access and stripped of inessentials.
>>
>> With commands like these:
>>
>> . sysuse auto
>> (1978 Automobile Data)
>>
>> . graph bar turn trunk , over(foreign) caption(whatever)
>>
>> . graph bar turn trunk , over(foreign) caption(whatever, pos(12))
>>
>> . graph bar turn trunk , over(foreign) caption(whatever, pos(12)
>> ring(0))
>>
>> I can move the caption around.
>
> Dorothy Bridges
>
>> My caption is appearing underneath (or on top of, I guess) the
>> category axis labels on my bar graph.  I can't fathom why (I've tried
>> specifying a different ring option, no luck).  My code is as follows:
>>
>> #delimit;
>> graph bar seriesAG-seriesMNF, over(year, label(labsize(medium)))
>> percentages stack
>> graphregion(fcolor(white) lcolor(white) margin(zero))
>> plotregion(fcolor(white) lcolor(white) ilcolor(white))
>> title("xxxx",color(black) placement(west) justification(left)
>> size(large))
>> caption("Sources: xxxx", size(vsmall) placement(west)
>> justification(left))
>> legend(cols(1) span position(3) stack region(lcolor(white)) title(" ",
>> size(small))
>> order(10 9 8 7 6 5 4 3 2 1) rowgap(7) keygap(1)
>> label(1 "Agriculture") label(2 "Mining, Oil & Gas") label(3
>> "Construction")
>> label(4 "Wholesale" "& Retail Trade") label(5 "Financial Services")
>> label(6 "Other Services") label(7 "Public Administration")
>> label(8 "Utilities") label(9 "Transport" "& Communication")
>> label(10 "Manufacturing"))
>> xsize(7.5) ysize(4.1)
>> ytitle("")
>> ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100
>> "100%",glwidth(thin) glcolor(black) angle(horizontal) labsize(medium))
>> ;
>
> *
> *   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/
>

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index