The example here is about how to do a small extra thing that's not implemented in a command of mine, but the moral is in the title. Sometimes an extra graphical thing doesn't seem to be supported by whatever you're using, but if a graphical command supports addplot(), perhaps you can use that as an open window to reach inside and add code without a need to modify the command, or hope or ask that someone does that.
As some long-term members may have spotted, I am big supporter of quantile plots as honest plots of distributions that come close to having all the virtues: showing the main features of a distribution, showing important detail, and not depending on arbitrary decisions such as choice of bin start, bin width, and so forth.
Recently I wanted to add some horizontal reference lines to qplot and feared that I would need to go into the code and add an extra option. I may yet do that, but there is no absolute need.
I am using qplot from the Stata Journal (q here means quantile*).
To get the means for groups in a new variable, I fire up egen. I need a variable that stretches from 0 to 1 and that's a further line. Then I can add a call to the addplot() option.
A further example would be showing a variable on a log scale with added geometric means. That could be price from the auto data. There is a geometric mean function in egenmore on SSC but no harm done if you didn't know that or can't download code.
and then you're away.
If you think you've read the same message just recently, you're right. https://www.statalist.org/forums/for...-interval-sets
(In R, the q of qplot() means quick. I don't know when that it was first named, but my qplot was first named in 2003, and I gather that qplot() in R is now deprecated. R users naturally don't need to worry about using our names, as we don't worry about using theirs.)
As some long-term members may have spotted, I am big supporter of quantile plots as honest plots of distributions that come close to having all the virtues: showing the main features of a distribution, showing important detail, and not depending on arbitrary decisions such as choice of bin start, bin width, and so forth.
Recently I wanted to add some horizontal reference lines to qplot and feared that I would need to go into the code and add an extra option. I may yet do that, but there is no absolute need.
I am using qplot from the Stata Journal (q here means quantile*).
Code:
sysuse auto, clear egen mean = mean(mpg), by(foreign) bysort foreign (mpg) : gen x = cond(_n == 1, 0, cond(_n == _N, 1, .)) qplot mpg, by(foreign, note(means shown) legend(off)) /// addplot(line mean x) xtitle(Fraction of data) xla(0 1 0.25 "0.25" 0.5 "0.5" 0.75 "0.75")
To get the means for groups in a new variable, I fire up egen. I need a variable that stretches from 0 to 1 and that's a further line. Then I can add a call to the addplot() option.
A further example would be showing a variable on a log scale with added geometric means. That could be price from the auto data. There is a geometric mean function in egenmore on SSC but no harm done if you didn't know that or can't download code.
Code:
egen gmean = mean(log(price)), by(foreign) replace gmean = exp(gmean)
If you think you've read the same message just recently, you're right. https://www.statalist.org/forums/for...-interval-sets
(In R, the q of qplot() means quick. I don't know when that it was first named, but my qplot was first named in 2003, and I gather that qplot() in R is now deprecated. R users naturally don't need to worry about using our names, as we don't worry about using theirs.)