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

st: Re: placing -xtitle- in a specific location in relation to the scale of the x-axis

From   Jacob Wegelin <>
Subject   st: Re: placing -xtitle- in a specific location in relation to the scale of the x-axis
Date   Sun, 3 May 2009 12:59:08 -0400

Here is one solution to the problem I posted a few minutes ago. This
email contains a detailed description of how I used the
point-and-click interface, the graph editor, and the graph editor
recorder, to change the graph to specifications.

The current solution ends with a -graph play- command, which I append
to my original do-file. The expanded do-file creates exactly the graph
I want without any further pointing or clicking. One must keep an
additional file on disk for this solution, a "graph editor recording"
file which ends in *.grec.

A remaining question: Is it possible to extract the pertinent
instructions from the *.grec file and simply include the in one's
do-file, rather than using a "graph play" command? Scott Merryman, in
his post of Sat, 18 Apr 2009 15:10:33 with subject "st: graph hbox Y,
by(something noiyaxes) over(grp2) over(grp1)", seems to have done

I found that it did *not* work to simply append my *.grec file to my
do-file. That generated an error.

Details of the graph editor solution:

After running the do-file in my original post (below), I did the following:

Click on the icon on the top of the graph that looks like a bar chart.
This signifies "edit".

Then the graph slightly changes appearance and a margin containing
text pushes out from the right side of the graph.

Click on the red button above the graph, which signifies "start recording."

On the right margin, click on "xaxis1".

Click on "More".

Click on "Title."

In the Text field, type in "Miles per gallon."

Click "Advanced."

In the "X offset" field, type in a number such as 15; then click
"apply." Keep trying different numbers until the x-axis title is right
where you want it. I found that -21.5 worked great.

Click OK and OK again to get back to the first "graph edit" position,
now with the title placed as we want it.

Click solidly on the red button again and then you're prompted for a
recording name. First browse to get to the directory ("folder") in
which you are working, then name it 20090503myedits.

Then a file called 20090503myedits.grec is saved to the directory that
you specified.

Then you can place the following line at the end of the commands (the
do-file) that created the original graph:

graph play 20090503myedits


On Sun, May 3, 2009 at 12:03 PM, Jacob Wegelin <> wrote:
> Is there a way to specify the horizontal location of the -xtitle- in
> relation to the scale of the x-axis?
> For instance, in the example below, for beauty of presentation I'd
> like to place the -xtitle- exactly at the midpoint between the
> quartiles of -mpg-. The code below *almost* does this, by calling both
> -xlabel- and -xmlabel- and pretending that my x-axis title marks a
> value on the x-axis. But the result is that the text "MPG" is too
> close to the plot region, i.e., too high up, squeezed between the
> numeric axis labels. It should lie below the numeric axis labels. If
> the text were "Miles per gallon" it would not fit between the numeric
> axis labels at all.
> Also, if one wanted to create two honest numeric axis labels (-xlabel-
> and -xmlabel-), I think the following workaround might interfere.
> Is there a way to specify straightforwardly that one wants one's
> -xtitle- to be located, for instance, where x==21.5 and a specific
> distance below the plot region?
> The graph editor allows me to place the -xtitle- at the far left
> ("southwest") or far right ("southeast") but does not seem to allow a
> specific numeric location with respect to the x-axis.
> sysuse auto, clear
> qui summarize mpg, detail
> local thisQ1=r(p25)
> local thisQ3=r(p75)
> local xtitlelocation= (`thisQ1'+`thisQ3')/2
> di `xtitlelocation'
> sort mpg
> kdensity mpg , gen(dnsMPGx dnsMPGy) nograph
> set scheme lean1
> twoway (line dnsMPGy dnsMPGx) ///
>   , xlabel(`xtitlelocation' "MPG", nogrid noticks labsize(large)) ///
>   xmlabel(`thisQ1' `thisQ3', grid glpattern(dash) labsize(medium)) ///
>   xtitle("") ///
>   plotregion(margin(zero)) ///
>   title("") ytitle("") ylabel(none)
> Thanks for any insights
> Jacob A. Wegelin
> Assistant Professor
> Department of Biostatistics
> Virginia Commonwealth University
> 730 East Broad Street Room 3006
> P. O. Box 980032
> Richmond VA 23298-0032
> U.S.A.
> E-mail:
> URL:

*   For searches and help try:

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