Hi,
I have issues with proc sgplot once again. I just couldn't find any proper papers nor examples on usage of the legend statement in proc sgplot. The SAS documentation is good, except it misses the instruction when/how and where to use it.
I have a graph with both series and scatter plots in it(both grouped with different group). The autolegend puts both of these in the same legend box, but what I would need to break the legend in pieces so that the series legend would be under the graph and the scatter legend on the mid left of the graph.
Any help is much appreciated, thanks.
Here's an example of something similar. Pick your names and locations as wanted.
proc sgplot data=sashelp.iris;
title "Iris Petal Dimensions";
scatter x=petallength y=petalwidth / name='one';
ellipse x=petallength y=petalwidth / name='two';
keylegend 'one' / location=inside position=bottomright;
keylegend 'two' / location=inside position=topright;
run;
Hi,
I don't have a solution to your problem, not come across it myself. I agree the documentation is a nightmare. If I need to find anything on sgplot, or probably in this case GTL would be better I refer to this blog: http://blogs.sas.com/content/graphicallyspeaking/
Is very good with examples in sgplot and gtl in most cases. Note its is a blog, so lots of separate posts, so keep looking through/trying search etc.
Hope that helps.
Here's an example of something similar. Pick your names and locations as wanted.
proc sgplot data=sashelp.iris;
title "Iris Petal Dimensions";
scatter x=petallength y=petalwidth / name='one';
ellipse x=petallength y=petalwidth / name='two';
keylegend 'one' / location=inside position=bottomright;
keylegend 'two' / location=inside position=topright;
run;
This is the best solution I guess, thanks. It puzzles me though why there is this LEGEND statement documented in the proc sgplot. And also there seems to be very very limited space that the keylegend uses to put the values.
For example in my case if there is more than 6 groups then the legend won't print out (there would be a lot of space though to do it because 6 group legend is only about half the plot size...) but I guess this is a problem for whole other thread.
Many times there are space limitations. Some options to fit things include modifying the style to use a smaller font, increasing the graph size (I know there may be limits imposed by others), changing the text displayed or going to a different procedure.
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 25. 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.