如何使用rcap更改双向图中的条形颜色?

时间:2019-05-15 19:20:44

标签: graph colors stata two-way

我正在尝试通过覆盖twoway bar来更改rcap图中条形的颜色。

Stata不允许我使用color()bcolor()bar(1, color())选项。

这是我的代码:

twoway (bar meanVAR1 Treatment) (rcap loVAR1 hiVAR1 Treatment), yscale(off) ///
ytitle(Percent) xtitle(Exp whether treated) xlabel(minmax) legend(off) ///
name(experience, replace) graphregion(fcolor(white) ifcolor(white)) ///
plotregion(fcolor(white) ifcolor(white))

如何更改图形中条形的颜色?

1 个答案:

答案 0 :(得分:1)

如果只想为所有条形指定颜色,则只需将color()选项放置在 twoway bar图的内部:

sysuse sp500, clear
by date: egen mean_open = mean(open)

twoway (bar mean_open date in 1/37, color(sand)) (rcap high low date in 1/37, color(ebblue))

enter image description here

如果要定义每个栏的颜色,则需要覆盖多个twoway bar图形并使用bcolor()选项,以便获得所需的输出,具体取决于根据您的数据:

twoway (bar mean_open date in 1/37 if date < `= daily("27/01/2001", "DMY")', bcolor(red)) ///
       (bar mean_open date in 1/37 if date > `= daily("27/01/2001", "DMY")', bcolor(orange)) ///
       (rcap high low date in 1/37, color(black))

enter image description here