我正在尝试创建一个条形图,我需要为特定的y值设置参考线。我可以用yline做到这一点:
graph bar libdem, over(country, sort(libdem) descending label(alternate)) ///
bar(1, color(gs10) lcolor(black) lwidth(medium)) ytitle("") yline(.3864677, lstyle(foreground)) ///
title("Liberal Democracy") ylabel(,gstyle(minor)) legend(off)
问题是参考线在后台并且不够可见。将它放在前景中,覆盖在条形图上会很不错。我试过了lstyle
,但它没有做到这一点。我看到this post类似的内容,但问题是我无法弄清楚如何使||
与over
一起工作
答案 0 :(得分:0)
Here's the code from the Statalist post you linked to
sysuse auto, clear
collapse mpg, by(rep78)
twoway bar mpg rep78, base(0) barw(0.6) || function y = 23, ra(0.7 5.3) ///
yla(0(5)40) legend(off) ytitle(Mean miles per gallon) xtitle(`: var label rep78')
and here's the proof that it works:
You don't provide a reproducible example and don't indicate explicitly what code you tried to add a horizontal line. But possible problems are evident:
The device above won't work with graph bar
. You do need to use twoway bar
instead.
Before you do that you will need to collapse libdem, by(country)
to get a dataset with means.
-- which are why the example was phrased as it was.