[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: logarithmic scales
At 16:04 27/11/03 +0000, Nick Cox wrote:
Here's a small issue which is utterly elementary, but it may
provide a moment's bemusement, and I'd welcome any comments.
When drawing graphs with one or both axes on a logarithmic scale,
Stata by default tries to provide "nice" labels, just as usual.
I'm writing a graphics program for a kind of plot in which one
axis will _always_ show a logarithmic scale, yet I find that
Stata's default for labels often gives me what is both a very
sensible and a very poor answer. The fault is possibly as much
mine as Stata's, as I may be quirky in what I most often want.
Also, despite years of acquaintance, Stata can't know what I
want unless I tell it.
I too have had a similar experience to Nick's, while writing my own
-smileplot- package (downloadable from SSC). My personal custom is to use
my own -explist- package (downloadable from SSC and modelled broadly on
Nick Cox's -listutil- suite) to define an exponentially spaced list of
numbers, with a logarithmic base defined by the -base()- option and a scale
defined by the -scale()- option. -explist- takes, as input, a list of
numbers x_1, ... , x_n, and creates, as output, a list of numbers y_1, ...
, y_n, derived exponentially from the input list, so that, for each i,
Any views on this, including reports on tribal attitudes or
y_i = scale*base^x_i
Therefore, if I want a scale that starts at 0.75 and has a tick at each
doubling, then I might type
. explist 0(1)10, scale(0.75) base(2)
. retu list
r(explist) : ".75 1.5 3 6 12 24 48 96 192 384 768"
If I want the scale to be a bit busier, then I might use multiple -explist-
lists with the same -base()- option and different -scale()- options, and
concatenate them in the -xlabel()- option of -graph twoway- as follows:
. sysuse auto, clear
(1978 Automobile Data)
. explist 0(1)2, base(2) scale(1000) global(g1)
. explist 0(1)2, base(2) scale(1500) global(g2)
. scatter length weight, xscale(log) yscale(log) xlab($g1 $g2)
and the X-axis labels will be -xlab(1000 1500 2000 3000 4000 6000)-.
This leaves the question of choosing the base, scale and input list for
-explist-. In the case of -smileplot-, the Y-axis variable is a P-value, so
I set the logarithmic scale to start from one and to end at
ceil(-log(pmin)/log(base)), where -pmin- is the smallest P-value. The
increments are chosen, by default, to keep the number of labels to no nore
than 25 (which was the largest number allowed by Stata 7). In the general
case, it is probably a good idea to use the -ceil()- function on the
maximum log (to the chosen base) and the -floor()- function on the minimum
log (to the same chosen base) to define the top and bottom of the scale,
and to choose the scale(s) and input list to optimise the number of tick
marks or labels by some criterion.
Lecturer in Medical Statistics
Department of Public Health Sciences
King's College London
5th Floor, Capital House
42 Weston Street
London SE1 3QD
Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
or 020 7848 6605 International +44 20 7848 6605
Opinions expressed are those of the author, not the institution.
* For searches and help try: