Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Different Label Positions for Different Bars in one Bar Chart


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Different Label Positions for Different Bars in one Bar Chart
Date   Mon, 10 Sep 2012 23:27:47 +0100

You may need to switch to -twoway bar- to get this.

Some technique:

sysuse auto, clear

graph hbar mpg, over(foreign) asyvars ///
blabel(name, position(base)) bar(1,color(gs8)) bar(2,color(gs12)) name(hbar)

local xtitle "`: var label mpg'"

collapse mpg, by(foreign)

gen zero = 0

twoway bar mpg foreign if foreign, horizontal base(0) bcolor(gs8)  ///
|| bar mpg foreign if !foreign, horizontal base(0) yla(0 1,
valuelabel) bcolor(gs12) yla(, noticks ang(h)) ///
|| scatter foreign mpg if foreign, ms(none) mla(foreign)  ///
|| scatter foreign zero if !foreign, ms(none) mla(foreign) ///
legend(off) xla(0(5)25)xsc(r(. 30)) xtitle(`xtitle') name(twbar)

Nick

On Mon, Sep 10, 2012 at 9:56 PM, Jan Keil <keil@gmx.us> wrote:
> Dear Statalist,
>
> I am trying to create an hbar chart where the labels are inside and at the base position for some bars while the labels of other bars are located outside.
> It seems to be the case that this can only be done for all bars at the same time. I did not find an easy way to do it but I am sure that there is a very trivial solution.
>
> The option for changing it for all graphs is blabel(name, position(base)).
>
> The whole command looks similar to this
>
> graph hbar costs, over(industry)
> asyvars blabel(name, position(base))
> bar(1,color(gs8)) bar(2,color(gs12))
>
>
>
> *
> *   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   |   Site index