Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: RE: Graphing Histograms and Overlaying A Vertical Line

 From Nick Cox To "statalist@hsphsun2.harvard.edu" Subject Re: st: RE: Graphing Histograms and Overlaying A Vertical Line Date Fri, 24 May 2013 19:05:21 +0100

```This is a trick worth knowing, and I will give it a puff because Elan

-twoway function- draws functions that are y (variable on vertical
axis) = whatever, and whatever can be a constant. But here the problem
is to draw a function x (variable on horizontal axis) = whatever, and
whatever is a constant. The option -horizontal- is what flips it
around. It's documented, but like so much that is documented, it can
easily be overlooked.

Thanks for the nice example.

Nick
njcoxstata@gmail.com

On 24 May 2013 18:48, Cohen, Elan <cohened@upmc.edu> wrote:
> I see now.  From http://www.stata-journal.com/sjpdf.html?articlenum=gr0014, the following should work:
>
> sysuse auto
> twoway__histogram_gen mpg, percent gen(h x)
> su h, meanonly
> loc max = 1.1*r(max)
> qui su mpg, d
> loc mean = r(mean)
> loc med = r(p50)
> tw hist mpg, percent || function y=`mean', hor ra(0 `max') || function y=`med', hor ra(0 `max')
>
>
*
*   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/
```