This seems like it should be an easy question, but I have been unable to find an option for this in SGPLOT (version 9.4 M5). I have a horizontal bar chart with very long category value labels (can't really shorten these, unfortunately). I have the Y Axis label set to appear on the top, but it appears above the value labels instead of the bars. I would like the label to be moved over to the right so it lines up with the box around the data. Here's my code (chart output is below):
proc sgplot data=lq_base NOAUTOLEGEND;
styleattrs DATACOLORS=(cxEAAA00 cx002855);
hbar ClusterName / response=employ_growth_us
group=employ_g_us
nooutline
barwidth=0.8;
xaxis DISPLAY=(NOLABEL)
VALUEATTRS=(Family=Calibri Size=8);
yaxis label="Location Quotient"
LABELATTRS=(Family=Calibri Size=8 Weight=Bold)
LABELPOS=TOP
discreteorder=data
type=discrete fitpolicy=none
VALUEATTRS=(Family=Calibri Size=8);
where ClusterCode<=51;
run;
I though there would be an easy way, but I couldn't find it.
What I did find was another thread with something similar. I'm not terribly sure how the solution of that thread works, but one of the other posts worked.
Here is the thread: https://communities.sas.com/t5/SAS-Enterprise-Guide/Locating-titles-inside-of-chart-area-in-proc-sgp...
I used Bryan's solution:
I also switched from your table to SASHELP.CARS so I could test the solution.
Looks like you can use another table as a way to annotate your visual using the sganno option in the proc sgplot statement.
Something like this? You'd have to dive a bit more into the columns to create to set similar formatting to what you have:
Data anno;
function="text";
x1space= 'graphpercent';
y1space= 'graphpercent';
width=400;
textweight='bold';
textsize=10;
y1=95;
x1=50;
label="Location Quotient";
output;
run;
proc sgplot data=sashelp.cars NOAUTOLEGEND sganno=anno ;
title 'test';
styleattrs DATACOLORS=(cxEAAA00 cx002855);
hbar Make / response=MSRP
group=Origin
nooutline
barwidth=0.8;
xaxis DISPLAY=(NOLABEL)
VALUEATTRS=(Family=Calibri Size=8);
yaxis label="Location Quotient"
LABELATTRS=(Family=Calibri Size=8 Weight=Bold)
LABELPOS=TOP
discreteorder=data
type=discrete fitpolicy=none
VALUEATTRS=(Family=Calibri Size=8);
run;
- Peter
I though there would be an easy way, but I couldn't find it.
What I did find was another thread with something similar. I'm not terribly sure how the solution of that thread works, but one of the other posts worked.
Here is the thread: https://communities.sas.com/t5/SAS-Enterprise-Guide/Locating-titles-inside-of-chart-area-in-proc-sgp...
I used Bryan's solution:
I also switched from your table to SASHELP.CARS so I could test the solution.
Looks like you can use another table as a way to annotate your visual using the sganno option in the proc sgplot statement.
Something like this? You'd have to dive a bit more into the columns to create to set similar formatting to what you have:
Data anno;
function="text";
x1space= 'graphpercent';
y1space= 'graphpercent';
width=400;
textweight='bold';
textsize=10;
y1=95;
x1=50;
label="Location Quotient";
output;
run;
proc sgplot data=sashelp.cars NOAUTOLEGEND sganno=anno ;
title 'test';
styleattrs DATACOLORS=(cxEAAA00 cx002855);
hbar Make / response=MSRP
group=Origin
nooutline
barwidth=0.8;
xaxis DISPLAY=(NOLABEL)
VALUEATTRS=(Family=Calibri Size=8);
yaxis label="Location Quotient"
LABELATTRS=(Family=Calibri Size=8 Weight=Bold)
LABELPOS=TOP
discreteorder=data
type=discrete fitpolicy=none
VALUEATTRS=(Family=Calibri Size=8);
run;
- Peter
I bet! I feel like there should be an easier way that we are missing. But glad you are getting it working!
- Peter
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.