I am using the following command to generate a horizontal stacked bar graph:
But I'm having a problem with the bar placement. According to the Stata documentation, specifying -position(inside)- will cause the label to appear at the right end of the corresponding bar. And for most of the bars, it does that. But there is one bar in the graph, a very short one, that is barely large enough to contain the label. And for that one, the label shows up left-justified in its bar, or, with some data inputs it ends up concatenated with the label in the bar immediately to its left. (Look at the rightmost bar segment for "Event 2" in the output above.
I'm able to patch up that bar using the Graph Editor, but I'm wondering if there's some way I can modify the code to make that manual step unnecessary.
(Please do not comment on the color scheme. I know it's garish.)
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input byte event float(level1 level2 level3 level4 level5 level6 level7 level8)
1 2558 . . . . . . .
2 . 1257 227 76 . . . .
3 . . . . 985 272 . .
8 . . . . . . 933 .
9 . . . . . . . 425
end
label values event event
label def event 1 "Study Event 1", modify
label def event 2 "Study Event 2", modify
label def event 3 "Study Event 3", modify
label def event 8 "Study Event 8", modify
label def event 9 "Study Event 9", modify
graph hbar (asis) level*, ///
over(event) stack ///
blabel(bar, size(vsmall) position(inside)) ///
ytitle(Count) name(totals, replace) legend(off) ///
bar(1, color(ltblue)) bar(2, color(cranberry)) bar(3, color(forest_green)) ///
bar(4, color(gray%25)) bar(5, color(khaki)) bar(6, color(olive%50)) ///
bar(7, color(pink)) bar(8, color(teal))
I'm able to patch up that bar using the Graph Editor, but I'm wondering if there's some way I can modify the code to make that manual step unnecessary.
(Please do not comment on the color scheme. I know it's garish.)

Comment