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

Hi everyone,

 

I was wondering how to display a single legend  for multiple plots when using ods layout gridded with proc sgplot.

 

Currently, as the code and graphic below show, I'm using keylegend which produces one legend for each plot. How can I display that same legend only once, below the title?

Thanks

 

ods powerpoint file="/u1/reporting_happy/testinggraphs.pptx" nogfootnote dpi=300 style=styles.mystyle;
/*Rows =8 forces A SECOND GRID PAGE*/
title1  "This is the title of the dummy slide" height=20pt;

ods graphics on / width=2.725in height=1.1in scale=on;
ods layout gridded columns=3 rows=8 advance=bygroup COLUMN_GUTTER=3pt ;
ods region;


	/*for each variablename */
	proc sgplot data=AllMVariables uniform=group noautolegend noborder pad=0 nocycleattrs;
		by variablename;
		scatter x=macvalue y=measurey / group=measure name="measure" grouporder=reversedata;
		keylegend "measure" / BORDER POSITION=top;
 	series x=macvalue y=measurey / group = measure name="measure" grouporder=ascending attrid=myid 
		lineattrs=(pattern=solid thickness=1) GROUPDISPLAY=CLUSTER clusterwidth=0.0;
		xaxis display=none;
		yaxis display=none;
		options nobyline;
		title "#byval1" ls=1.5 height=12pt;
	run;

ods layout end;
ods powerpoint close;
quit;
;

SAS Results Graph3.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
happy_mouth
Obsidian | Level 7

Thanks for your help, PG.

 

I contacted tech support and they suggested that I manually create a title with legend information, like this:

 

title2  box=2 c=cxFAC090 h=20pt "(*ESC*){unicode '25cf'x}" h=12pt c=black ' Boston '

c=cx4F6228 h=20pt "(*ESC*){unicode '25cf'x}" h=12pt c=black ' Denver '

c=cx1F497D h=20pt "(*ESC*){unicode '25cf'x}" h=12pt c=black ' Seattle;

 

This works OK with SGPLOT,

 

Thanks again.

 

View solution in original post

6 REPLIES 6
PGStats
Opal | Level 21

Is there a reason why you can't move this to SGPANEL?

PG
happy_mouth
Obsidian | Level 7

I tried using the same code with sgpanel. It worked for my toy case, but when I applied it to my real use case (with three scatter plots and two series plots per group), only one marker per plot was displayed. 

 

thanks,

Dave

PGStats
Opal | Level 21

But sgpanel should work and would be the way to go. Sgpanel can draw many plots, each involving many groups, in every graph cell of a panel.

PG
happy_mouth
Obsidian | Level 7

Hi PG,

 

Thanks for your replies.

 

When I try using SGPANEL, I get the legend outside the rest of the plot, as I want, thanks, but there is a problem with the X-axis scaling in some of the subplots. The scale of the axis seems to be set by something other than then the minimum and maximum values of the group (maybe the max\min of the column???). (See code and result below.) Scaling works fine with SGPLOT; is there a way to control the scaling in SGPANEL so the x-axis range is determined by min and max values in each cell?

 

thanks,

Dave

 

Important part of code:

ods powerpoint file="/u1/pretendpath/testinggraphs.pptx" nogfootnote dpi=300 style=styles.mystyle;
/*Rows =8 forces A SECOND GRID PAGE*/
title  "This is the title of the dummy slide" height=20pt;

ods graphics on / width=8.8in height=4.87in scale=on;

proc sgpanel data=AllMVariables dattrmap=scenarioattrs noautolegend pad=0 nocycleattrs;
	panelby variablename /  layout=panel columns=3 rows=4 novarname uniscale=row;
	colaxis display=none;
	rowaxis display=none;

 	series x=macvalue y=measure / group = measure name="measure" grouporder=ascending attrid=myid 
		lineattrs=(pattern=solid thickness=1) GROUPDISPLAY=CLUSTER clusterwidth=0.0;
 	series x=macvalue y=measure / group = measure name="measure" grouporder=ascending attrid=myid 
		lineattrs=(pattern=solid thickness=7) GROUPDISPLAY=CLUSTER clusterwidth=0.0;

	scatter x=macvalue y=measure / group=measure name="measure" grouporder=ascending attrid=myid 
		 filledoutlinedmarkers markerattrs=(symbol=CircleFilled size=15) GROUPDISPLAY=CLUSTER clusterwidth=0.0;
		keylegend "measure" / BORDER POSITION=top;
run;

 

 

SAS Results Graph4.PNG

 

 

PGStats
Opal | Level 21

Looking at your example, it looks like option UNISCALE=ROW in the PANELBY statement might do the trick.

PG
happy_mouth
Obsidian | Level 7

Thanks for your help, PG.

 

I contacted tech support and they suggested that I manually create a title with legend information, like this:

 

title2  box=2 c=cxFAC090 h=20pt "(*ESC*){unicode '25cf'x}" h=12pt c=black ' Boston '

c=cx4F6228 h=20pt "(*ESC*){unicode '25cf'x}" h=12pt c=black ' Denver '

c=cx1F497D h=20pt "(*ESC*){unicode '25cf'x}" h=12pt c=black ' Seattle;

 

This works OK with SGPLOT,

 

Thanks again.

 

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 3147 views
  • 1 like
  • 2 in conversation