Thanks as always to Kit Baum, a new program niceloglabels is now available from SSC. It's written for Stata 11 up.
The purpose of the command is (surprise) nice log labels, meaning nice axis labels when using logarithmic scales.
Here is a reproducible example showing the problem.
The first graph G1 shows what often happens with log scales in graph when the variable concerned varies over a wide range, as it does with state populations in the United States. ysc(log) means only that graph is smart enough not to try to show 0 on a log scale; otherwise the labels are good for a linear scale, but can be too bunched up to appeal, or even not readable at all.
For some years, no some decades, I just fixed this on the fly by thinking up better labels ad hoc. But writing a helper program always seemed like a small project worth doing.
The purpose of niceloglabels is to suggest nice(r) labels but you have to tell it your idea of nice, as a style of labels you prefer. I specified 125 as a style here and if that's cryptic then example output should make it clearer:
The leading digits cycle over 1 2 5 within the range of the data. The result is better but still not ideal. One solution not shown here would be to scale to millions, and then show 0.5 1 2 5 10 20 as labels.
Another solution is to use power notation. The second niceloglabels call emits the syntax labels using superscript notation
This is where niceloglabels may start to seem useful. Even if you recall the syntax typing out the {sup: } stuff is not the most fun you can have without laughing. It's tedious and error-prone. All you have to do is put the label syntax in a local macro (a kind of bag, if you've not met that idea before) and then refer to the local macro in the graph call. Rather oddly, Stata doesn't seem to support the multiplication sign as a special symbol (tell me what I missed), so I am just using lower case x.
There is more. You can specify a range and the program will suggest labels for that range:
I needed that for real with a country population variable that ranged from 57 (Pitcairn) to 1387 million (China).
An earlier try at this problem some years ago didn't reach launch stage, partly because it seemed hard to find consensus about nice labels on logarithmic scales. Several styles can be found in the literature and even more adhockery hinging mostly on some pragmatism not showing labels that are too close to their neighbours.
As issued now, niceloglabels supports these styles
1 means powers of 10 such as ..., 0.1, 1, 10, 100, 1000, ...
13 means cycling such as ..., 0.3, 1, 3, 10, 30, 100, 300, ...
15 means cycling such as ..., 0.5, 1, 5, 10, 50, 100, 500, ...
125 means cycling such as ..., 0.1, 0.2, 0.5, 1, 2, 5, 10, ...
147 means cycling such as ..., 0.1, 0.4, 0.7, 1, 4, 7, 10, ...
2 means powers of 2 such as ..., 1, 2, 4, 8, 16, ...
but if there are principled alternatives, or even alternatives that are strong conventions in some fields, I am interested to hear of them.
The purpose of the command is (surprise) nice log labels, meaning nice axis labels when using logarithmic scales.
Here is a reproducible example showing the problem.
Code:
sysuse census, clear local noref rlopts(lc(none)) quantile pop, ysc(log) `noref' name(G1) niceloglabels pop , local(yla) style(125) quantile pop, ysc(log) yla(`yla', ang(h)) `noref' name(G2) niceloglabels pop , local(yla) style(125) powers quantile pop, ysc(log) yla(`yla', ang(h)) `noref' name(G3)
For some years, no some decades, I just fixed this on the fly by thinking up better labels ad hoc. But writing a helper program always seemed like a small project worth doing.
The purpose of niceloglabels is to suggest nice(r) labels but you have to tell it your idea of nice, as a style of labels you prefer. I specified 125 as a style here and if that's cryptic then example output should make it clearer:
Code:
. niceloglabels pop , local(yla) style(125) 500000 1000000 2000000 5000000 10000000 20000000
Another solution is to use power notation. The second niceloglabels call emits the syntax labels using superscript notation
Code:
. niceloglabels pop , local(yla) style(125) powers 500000 "5x10{sup:5}" 1000000 "10{sup:6}" 2000000 "2x10{sup:6}" 5000000 "5x10{sup:6}" 10000000 "10{sup:7}" 20000000 "2x10{sup:7}"
There is more. You can specify a range and the program will suggest labels for that range:
Code:
. niceloglabels 1e2 1e9, local(yla) style(1) powers 100 "10{sup:2}" 1000 "10{sup:3}" 10000 "10{sup:4}" 100000 "10{sup:5}" 1000000 "10{sup:6}" 10000000 "10{sup:7}" 100000000 "10{sup:8}" 1000000000 "10{sup:9}"
An earlier try at this problem some years ago didn't reach launch stage, partly because it seemed hard to find consensus about nice labels on logarithmic scales. Several styles can be found in the literature and even more adhockery hinging mostly on some pragmatism not showing labels that are too close to their neighbours.
As issued now, niceloglabels supports these styles
1 means powers of 10 such as ..., 0.1, 1, 10, 100, 1000, ...
13 means cycling such as ..., 0.3, 1, 3, 10, 30, 100, 300, ...
15 means cycling such as ..., 0.5, 1, 5, 10, 50, 100, 500, ...
125 means cycling such as ..., 0.1, 0.2, 0.5, 1, 2, 5, 10, ...
147 means cycling such as ..., 0.1, 0.4, 0.7, 1, 4, 7, 10, ...
2 means powers of 2 such as ..., 1, 2, 4, 8, 16, ...
but if there are principled alternatives, or even alternatives that are strong conventions in some fields, I am interested to hear of them.
Comment