Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Graph: hbar and yline

From   Ulrich Kohler <>
Subject   Re: st: Graph: hbar and yline
Date   Mon, 19 Dec 2005 10:07:26 +0100

Maarten buis wrote:
> This is indeed one of the less nice features of Stata graphs, but there is
> a way around it, which has been recently discussed on the list, see:
> At Sat 12/17/2005 9:03 PM Sergio Correia wrote:
> > I want to make an horizontal bar (hbar) with a line indicating
> > some key value. However, I want the line to be OVER the bar
> > values.

Maartens answer refers to the -addplot- option, which is unavailable for 
-graph hbar-, as far as I know. You might also give -graph twoway bar- a try. 
Consider the command

. sysuse auto
. graph hbar (mean) trunk, over(rep78, sort((mean) trunk)) yline(10)

This can be translated to -graph twoway bar- as follows:

. collapse (mean) trunk if rep78<., by(rep78)
. egen axis = axis(trunk), reverse label(rep78)  // <- Download -egenmore-
. graph twoway 
    bar trunk axis, horizontal barwidth(.5) 
    xscale(range(0 16)) xlabel(0(5)15)

You can than overlay any -twoway- plot you like. In your case overlaying a 
simple line graph is the most natural choice:

. gen line = 10
. graph twoway 
  || bar trunk axis, horizontal barwidth(.5) 
  || line axis line, sort 
  || , xscale(range(0 16)) xlabel(0(5)15) 

Note that the order of the overlays define what is graphed on top of each 

Hope this helps

+49 (030) 25491-361
*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index