worldbank/ietoolkit

iegraph : color() has no effect in baroption() option

kbjarkefur opened this issue · 2 comments

Issue submitted by email from @oscarmdiazb :

For a while, I've been trying to change the colours of the bars when using the iegraph command, but without success. Would you mind providing an example? I've tried the variations of the following code:

sysuse auto, clear 
reg price foreign 
iegraph foreign,  varlabels legend(pos(6) rows(1)) baroptions(color(green))     barlabel barlabelformat( %9.2f)

The error reproduces as submitted by user.

The fix was quite straightforward and is implemented in f4ac0a1.

OP followed up and suggested that baroptions() should be possible to set colors for individual bars. This is not possible using baroptions() as the bar options specified in that option is added to all bars.

Instead, in 0bfb72c a new option barcolors() was added. This option allows the user to manually specify colors, as in barcolors(`" red gs14 "215 25 28" gold cranberry "'). Any color listed in
https://www.stata.com/manuals13/g-4colorstyle.pdf may be used.

Test this option like this:

sysuse auto, clear
replace foreign = floor(runiform()*5)

gen f1 = (foreign == 1)
gen f2 = (foreign == 2)
gen f3 = (foreign == 3)
gen f4 = (foreign == 4)
gen ctrl = (foreign == 5)
 
reg price f1 f2 f3 f4 weight
iegraph f1 f2 f3 f4 , legend(pos(6) rows(1)) barcolors(`" red gs14 "215 25 28" gold cranberry "') barlabel barlabelformat( %9.2f) mlabcolor(blue) 

If barcolors() is used together with baroptions(color(green)) then the later takes precedence, as baroption() has the highest precedence to allow the user to overwrite any options used.