I think I already know the answer to this but thought I would ask just in case I'm missing something obvious or a new option in 9.4 that I have missed. Using SGPLOT (9.4 M02), for stacked vertical bar charts there seems to be no (easy) way of getting the legend entries to be in the same visual order (top to bottom or bottom to top) as the stacks themselves, using a numeric variable with formats applied for the stacks. Unfortunately, the default order of legend entries when the entries are going down, is the opposite to the (visual) order of the stacks. This is a shame as it seems the opposite of good graphing principles. I am in Australia though so maybe having the legend entries the way we need in our publications is an upside down Southern hemisphere thing 🙂 To enable us to meaningfully order stacks in stacked vertical bar charts, we always use a numeric group variable, with format applied to get the legend entry texts. After all how often is alphabetical order really meaningful? Default: With a stack variable with values 1 to 4 the stacks go UP from 1 to 4 but the legend entries appear in the opposite order going DOWN from 1 to 4. GROUPORDER: If we change GROUPORDER to descending in the VBAR statement, the stacks go DOWN from 1 to 4, but the legend entries go UP from 1 to 4. Some very simple code to illustrate what happens when we use both descending order options on VBAR and KEYLEGEND: data temp; z=1; x=1; y=20; output; x=2; y=25; output; x=3; y=10; output; x=4; y=15; output; run; proc format; value xfmt 1='This' 2='That' 3='Other' 4='Something else'; run; proc sgplot data=temp; vbar z/group=x groupdisplay=stack response=y name="vbar" barwidth=0.5 grouporder=descending; keylegend "vbar"/position=topright noborder location=inside down=4 sortorder=descending; format x xfmt. run; The bar order is based on the underlying number, but the legend order is based on the formatted values. To do something which was simple in SAS/Graph (ie get the formatted legend entries in the correct (visual) order based on the underlying unformatted value), is using GTL and typing in each legend entry the only option? If so is it likely that use of unformatted order for legend entries in SGPLOT could be implemented in future releases?
... View more