Apologies if this is a repeat. The forum site crashed after I hit 'submit'.
I would like to make a bar graph with bars of different colors. The context is that the height of the bars is a performance metric of each of 10 hospitals. I would like to send a graph to each hospital, showing their performance in one color (red) and the other hospitals would be unidentified and all another color (black for example) . I could of course send a bar graph with 10 bars and say "you are bar number 4" or "you are bar number 7" but that is not very visually appealing.
I tried plotSetGroupingBehavior() but that had no effect. I tried making all the bars red, then overlaying black bars on top of all but one of the others. No luck either.
Any help would be appreciated. Thank you
One way to do this would be to plot two sets of stacked bars. One set of bars will be all zeros, except for the highlighted hospital. The second set of bars will have a zero for the highlighted hospital only.
You can use plotSetBarStacked like this:
new; labels = "alpha" $| "beta" $| "gamma" $| "delta"; y = rndi(rows(labels), 1, 1|9); // This is the one that we will make stand out reference_label = "gamma"; struct plotControl plt; plt = plotGetDefaults("bar"); // Stack the two sets of bars on top of each other plotSetBarStacked(&plt, 1); plotSetLineThickness(&plt, 0); opacity = 0.5; solid_fill = 1; plotSetFill(&plt, solid_fill, opacity, "black" $| "red"); // Create a 'y' vector where all the reference label // is zero and another where all labels EXCEPT for // the reference label are zero. mask = labels .$== reference_label; y1 = y .* (mask .== 0); y2 = y .* mask; plotBar(plt, labels, y1~y2);
Perfect! Thanks so much - both for how quickly you answered as well as how well this code works.