Hello
I have been trying and searched all around the internet how to code this, I am pretty sure it is simple but i am going in circles and hope that someone here can help me
notably i tried to follow the advice here, unsuccessfully https://blogs.sas.com/content/graphicallyspeaking/2016/02/04/legend-order/
I am trying to invert the order of the legend of the attached plot so it matches that of the bars - as you can see for now you have in the plot the legend starts with Staphylococcus aureus on top, when in the plot it is at the bottom. It would be much more readable if the order of the legend matched that of the plot
thanks in advance
regards
Alex
ods html image_dpi=300;
title Frequency of pathogens by location of onset;
proc sgplot data=klfig.path;
vbar location / response=Percent group=Pathogen groupdisplay=stack SEGLABELFORMAT=percent10.1 seglabel grouporder=reversedata;
xaxis discreteorder=data;
yaxis grid values=(0 to 1 by 0.1) label="Percentage of each Pathogen" discreteorder=data;
keylegend / location=outside position=right across=1 title="order needs inverted";
run;
The REVERSEAUTO option on the KEYLEGEND should get you what you want. Here is a simple example
proc sgplot data=sashelp.cars;
vbar origin / response=msrp group=type name="type";
keylegend "type" / sortorder=reverseauto position=right;
run;
The REVERSEAUTO option on the KEYLEGEND should get you what you want. Here is a simple example
proc sgplot data=sashelp.cars;
vbar origin / response=msrp group=type name="type";
keylegend "type" / sortorder=reverseauto position=right;
run;
thank you very much 🙂
Glad you asked this question - sorting the legend like this should be a "best practice" imho.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.