[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: graph added text behaving strangely

From (Vince Wiggins, StataCorp)
Subject   Re: st: graph added text behaving strangely
Date   Mon, 29 Oct 2007 15:16:51 -0500

Dan Weitzenfeld <> writes that when he adds three
pieces of text to a horizontal bar chart and keeps the first position constant
for each piece of text, the pieces of text are not on a horizontal line.

Dan provides the following code, which reproduces the problem

> . sysuse auto,clear
> . graph hbar mpg, over(head)
>         text( 20 25 "20_25"  20 15 "20_15" 20 10 "20_10")

This is a bug.  It will be fixed in a future update.

I have one further comment and one easy workaround.


There is one nuance to horizontal bar charts, and that nuance means that Dan
will still have to make one small change to his expectations.  When you
specify coordinates on a horizontal bar graph (including those for the
location of added text), you do so as though the graph were still horizontal.
Put another way, it is the horizontal axis on a horizontal bar graph that is
called the y axis.  So, the y-axis is always the axis that measures the height
of the bars, regardless of whether the graph is vertical or horizontal.

Why?  So that you can switch a standard vertical bar chart to a horizontal bar
chart without having to reverse any coordinates that you specify on the
command.  At one time, we even considered calling the "y" axis the "scale"
axis on bar charts to make clear that it could switch directions.

So, when the fix is in Dan should flip each of his coordinates and code.

  . graph hbar mpg, over(head)
          text(25 20 "20_25"  15 20 "20_15" 10 20 "20_10")

if he wants his text all in a horizontal row.  If he wants a vertical row,
he should leave the -text()- option as it is.


The bug with the option -text()- on horizontal bar charts is that it is only
handling the first coordinate correctly.  That is why Dan's text does not fall
on a line.  Because the -text()- option can be repeated, Dan can type,

  . graph hbar mpg, over(head) text(25 20 "20_25")  text(15 20 "20_15")
                               text(10 20 "20_10")

to get text aligned horizontally.  

Or, he can type,

  . graph hbar mpg, over(head) text(20 25 "20_25") text(20 15 "20_15")
                               text(20 10 "20_10")

to align the text vertically.

-- Vince

*   For searches and help try:

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