BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BobHope
Quartz | Level 8

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

ballardw
Super User

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;

BobHope
Quartz | Level 8

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.

ballardw
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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