BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
AlexisT1
Calcite | Level 5

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;

Pathogens.png

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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;

View solution in original post

3 REPLIES 3
DanH_sas
SAS Super FREQ

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;
AlexisT1
Calcite | Level 5

thank you very much 🙂

GraphGuy
Meteorite | Level 14

Glad you asked this question - sorting the legend like this should be a "best practice" imho.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 617 views
  • 4 likes
  • 3 in conversation