Axis labels or ticks on specified scales
mylabels lbllist , myscale(transformation_syntax) local(macname) [ format(format) prefix(text) suffix(text) ]
myticks ticklist , myscale(transformation_syntax) local(macname)
mylabels and myticks generate axis labels and ticks on specified scales. Their use is best explained by examples, as below. Note that the label list lbllist and tick list ticklist will be expanded if presented as legal numlists and left as specified otherwise.
You draw a graph and one axis is on a transformed square root scale. You wish the axis labels to show untransformed values. For some values this is easy; for example, ylabel(0 1 2 "4" 3 "9" 4 "16" 5 "25") says use "4" as label for 2, and so forth. For other values and/or other transformations the conversion may be more difficult to do in your head, so that a dedicated utility is helpful.
The idea behind mylabels is that you feed it the labels (usually, but not necessarily, numeric labels) that you want shown and the transformation being used. It will then place the appropriate specification in a local macro which you name. You may then use that local macro as part of a later graph command.
So suppose that you want labels 0 1 4 9 16 25 36 49, and your data are square roots of these. Your call is mylabels 0 1 4 9 16 25 36 49, myscale(sqrt(@)) local(labels). Or suppose you want percents shown, and your data are proportions 0-1. Your call is mylabels 0(25)100, myscale(@/100) local(labels). Think of this in the following way: my graph labels that I want are 0(25)100, but my data scale is that of the labels divided by 100.
For a more challenging example, see the graph on Gabriel Rossman's blog at http://codeandculture.wordpress.com/2010/02/08/memetracker-into-stata/
Here the x axis variable is a date-time and the x axis labels shown are nice numbers in terms of clock time in milliseconds but by any other standard are arbitrary and awkward. The dates span a period in late 2008 and early 2009, so monthly labels would seem more natural (even though not regularly spaced in terms of clock time). An example is then mylabels "1 Aug 2008" "1 Sep 2008" "1 Oct 2008" "1 Nov 2008" "1 Dec 2008" "1 Jan 2009" "1 Feb 2009", myscale(clock("@", "DMY")) local(labels)
A similar idea may be used for axis ticks.
myscale() specifies the transformation used to produce the data you have. Stata syntax should be used with @ as placeholder for original value. To show proportions as percents, specify myscale(@/100). If no transformation is being used, specify myscale(@). This is a required option.
local(macname) inserts the option specification in local macro macname within the calling program's space. Hence that macro will be accessible after mylabels or myticks has finished. This is helpful for subsequent use with graph or other graphics commands. This is a required option.
format() specifies a format controlling the labels. This is a rarely specified option. It may be necessary to enforce the presentation of leading zeros.
prefix() specifies text to be prepended to all axis labels. Specify any blank spaces within " ".
suffix() specifies text to be appended to all axis labels. Specify any blank spaces within " ".
. mylabels 0(10)100, myscale(sqrt(@)) local(myla) . myticks 5(10)95, myscale(sqrt(@)) local(myti) . spikeplot ... , root yla(`myla', ang(h)) ymtic(`myti')
. mylabels 0(5)20, local(labels) myscale(@/100) suffix(" %") . mylabels 0(5)20, local(labels) myscale(@) prefix($)
. su mpg . mylabels -1/3, myscale(`r(mean)' + (@) * `r(sd)') local(labels) . histogram mpg, xaxis(1 2) xla(`labels', axis(2) grid) xtitle(z scale, axis(2)) normal
Nicholas J. Cox, Durham University email@example.com
The idea behind these programs may be traced to a program by Patrick Royston (1996). A question from Richard Campbell led to the last example above. A question from Clive Nicholas and a suggestion by Philippe van Kerm led to a correction and further comments above. A question from Richard Goldstein led to the prefix() and suffix() options. An example on Gabriel Rossman's blog, as noted above, provided a stimulus to generalise the program.
Royston, P. 1996. Flexible axis scaling. Stata Technical Bulletin 34, 9-10 (and in STB Reprints 6, 34-36). Freely accessible at http://www.stata.com/products/stb/journals/stb34.pdf
Online: help for axis_label_options