Dear Forum,

I would like to plot a stacked bar graph of an "outcome" over hiv status (positive vs. negative) and stratified by sex (male vs. female).

The "outcome" is in fact 3 separate variables ("low", "mid" and "hi") generated from an ordinal yvar with 3 levels ("1" "2" and "3"):
  • low = 1 if yvar==1
  • mid = 1 if yvar==2
  • hi = 1 if yvar==3
My specific goal - for which I seek guidance - is that I would like to (i) color code the bars according to HIV status (negative = navy; positive = maroon), while (ii) indicating the stacked bars "low" (100%) "mid" (20%) and "hi" (70%) by varying the opacity of their color, and lastly (iii) to generate a commensurate legend.

I have the below written stacked box plot command:

- graph bar (sum) cvd_low cvd_mid cvd_hi, over(hiv) over(sex) percent legend(label(1 "Low (<10%)") label(2 "Intermediate (10-30%)") label(3 "High (≥30%)") order(1 - "" 2 - "" 3)) stack

The output is also copied below.

Array


The goal is to have, for example, a navy "HIV negative" bar with different levels of outcome (cvd risk) indicated by different opacities (or shades) of the navy. I will very much appreciate any suggestions you may have on how to go about this.

Thanks in advance.

Itai