Controlling LEGENDs in PROC SGPLOT

Accepted Solution Solved
Reply
Contributor
Posts: 59
Accepted Solution

Controlling LEGENDs in PROC SGPLOT

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.


Accepted Solutions
Solution
‎08-18-2014 11:48 AM
Grand Advisor
Posts: 10,210

Re: Controlling LEGENDs in PROC SGPLOT

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;

View solution in original post


All Replies
Esteemed Advisor
Esteemed Advisor
Posts: 7,203

Re: Controlling LEGENDs in PROC SGPLOT

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.

Solution
‎08-18-2014 11:48 AM
Grand Advisor
Posts: 10,210

Re: Controlling LEGENDs in PROC SGPLOT

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;

Contributor
Posts: 59

Re: Controlling LEGENDs in PROC SGPLOT

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.

Grand Advisor
Posts: 10,210

Re: Controlling LEGENDs in PROC SGPLOT

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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