要向graph box 添加文本,请使用记录在案的text() 选项。这是一个可重现的例子。除了使用图表编辑器之外,除了摆弄看起来足够好的东西之外,我没有任何计算文本位置的方法。
sysuse auto, clear
gen logprice = log10(price)
ssc install mylabels
su price
mylabels 3000(2000)15000, myscale(log10(@)) local(yla)
graph box logprice, over(foreign) yla(`yla', ang(h)) ///
text(4.25 21.2 "{it:n} = 52") text(4.25 79.8 "{it:n} = 22") ///
ysc(r(. 4.3)) scheme(s1color) ytitle(Price (USD))
注意。要正确显示微克的 mu,请参阅 Stata 中的help graph text 并搜索希腊字母。
编辑
来自 SSC 的stripplot 也可以生成箱线图,尽管它的默认值和可能性都与graph box 不同。这是一个可重现的例子。
sysuse auto, clear
egen count = count(mpg), by(rep78)
gen where = 10.5
stripplot mpg , box vertical ms(none) pctile(5) over(rep78) ///
yla(12 41 15(5)40, ang(h)) ///
addplot(scatter where rep78, mla(count) ms(none) mlabpos(0) ///
mlabsize(medsmall)) scheme(s1color)
同样,尽管这是可重现的代码,但选择 10.5 是由于与此处未显示的其他值一起使用的结果。您可以尝试通过基于样本最大值和最小值的计算来自动选择,当然还有您对它应该在哪里的偏好。如果您要生产数十个这样的产品,那将是一个好主意。对于论文或演示文稿的单一情节,我只会玩。