We have used proc sgpanel to create heatmap. Although have used sortorder=descending in the keylegend statement, the legend is not sorted as per the expectation, i.e. 4,3,2,1,0,-1,-2,-3,-4.
I have tried using proc sort with force option to sort the attrmap dataset, but that didn't help either.
Any help/suggestions would be much appreciated.
/* Define attribute map for CHG value colors */
data attrmap;
length id $20 value 8 fillstyle $10 fillcolor $20;
id='colormap';
value=-4; fillstyle='solid'; fillcolor='DELG'; output;
value=-3; fillstyle='solid'; fillcolor='VILG'; output;
value=-2; fillstyle='solid'; fillcolor='BILG'; output;
value=-1; fillstyle='solid'; fillcolor='LIGY'; output; /* brown */
value= 0; fillstyle='solid'; fillcolor='white'; output;
value= 1; fillstyle=
'solid'; fillcolor='cxfca5a5'; output;
value= 2; fillstyle='solid'; fillcolor='cxfb7171'; output;
value= 3; fillstyle='solid'; fillcolor='RED'; output;
value= 4; fillstyle='solid'; fillcolor='VIPK'; output;
run;
proc sgpanel data=out.HeatmapF noautolegend dattrmap=attrmap;
panelby trt_label_sort / sort=descending layout=columnlattice onepanel colheaderpos=top novarname uniscale=row proportional;
heatmapparm x=ordern y=paramcd_label colorgroup=CHG / attrid=colormap outline discretex discretey;
keylegend / position=bottom title="Change from Baseline" sortorder=descending ;
colaxis grid label="Subject" valueattrs=(size=3.5);
rowaxis min=0 max=200 label=" PART 2 PART 1 " reverse;
run;
Changing sortorder from descending to reverseauto helped:
keylegend / position=bottom title="Change from Baseline" sortorder=reverseauto;
The easiest way to get what you want here is to add the following following line to your ATTRMAP data step and get rid of the sort option:
retain show "attrmap";
This will populate the legend with the values from the attributes map -- in the order you listed them.
Hope this helps!
Thanks @DanH_sas. I added the retain statement, but unfortunately still no change in the order on the legend.
Changing sortorder from descending to reverseauto helped:
keylegend / position=bottom title="Change from Baseline" sortorder=reverseauto;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.