Hi,
When using proc sgplot, are those statements correct?
When a legend has position=right:
1/ Legend title: As far as I could see there is not titlealign available in keylegend to left align the legend title; legenditem is only for the values. So the only solution would be using text annotation.
2/ Legend: padding between values is not possible
Axis
3/ Axis and tick colors: it is not possible to change it.
4/ It is not possible to define the distance between the axis and the values (e.g y-axis in a vertical bar chart)
It would be better if you could post a graphic to illustrate your question.
The following is for your first three questions.
The last question you could try YAXISTABLE statement.
https://blogs.sas.com/content/iml/2019/09/11/axis-tables-rotated-text.html
data have;
set sashelp.heart;
_s=ifc(status='Dead','xxxxxxxxxxvvvxxxx','yyyyxxxyyyyyyy');
run;
ods html style=sasweb;
proc sgplot data=have ;
scatter x=weight y=height/group=_s ;
keylegend / position=right title='ss ';
run;
ok. So trailing blanks solve problem 1 when we know in advance how many blanks are needed. Thanks.
But you example does not show how to modify the padding above/below each value of the legend item.
It also does not show how to change the color of the axis and ticks on the axis.
When it comes to yaxistable, I doubt it would solve the problem with a linear axis.
@xxformat_com wrote:
ok. So trailing blanks solve problem 1 when we know in advance how many blanks are needed. Thanks.
But you example does not show how to modify the padding above/below each value of the legend item.
It also does not show how to change the color of the axis and ticks on the axis.
When it comes to yaxistable, I doubt it would solve the problem with a linear axis.
Please do not complain about missing items when you have not 1) provided base Sgplot code to modify, 2) data for that to plot 3) clear description of how much "padding" and exactly where it would go 4) any particular rules on "change the color of the axis and ticks on the axis"
Note that if you need more control than SGPLOT XAXIS statement supplies then you can move the Graphic Template Language which has more axis controls such as TICKVALUEATTRS
Here is a link to an example that uses an annotate data set to replace tick mark values with text, in different colors, for each value displayed including unicode character as part of the "tick mark".
The AXIS line colors are controlled by the Style in effect and is set in the definition of class GraphAxisLines so feel free to modify the axis definition in the style of your base style.
Note that the more control over specific elements you want the more you have to do to get there.
There was no complain on my side. If it has offended someone, I apologize as it was not the intention.
I just assumed that the question was obvious as it was the default setting by all bar charts.
The four points here was just to make sure I didn't miss any option. There are so many options and what some are doing it not clear to me upfront.
It's good to know that GTL offers more flexibilty. I haven't dive into proc template yet.
"But you example does not show how to modify the padding above/below each value of the legend item."
You could try VALUESATTRS= option.like this:
proc sgplot data=have ; scatter x=weight y=height/group=_s ; keylegend /valueattrs=( size=12 family='courier') position=right title='ss '; run;
If it was not fit your demand, yes, you should try text annotation.
"It also does not show how to change the color of the axis and ticks on the axis."
As ballardw pointed out , GTL could do it , text annotation also can do it .
"When it comes to yaxistable, I doubt it would solve the problem with a linear axis."
Check this:
https://blogs.sas.com/content/iml/2019/09/11/axis-tables-rotated-text.html
If it is still not fit your requirement, yes , try text annotation.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: