BookmarkSubscribeRSS Feed
DinoPut
Obsidian | Level 7

Hi

 

I am trying to create a 2 panel plot with each of the panels displaying different data. However when I'm unable to create a separate merged legend for each of the panels with the treatment information within each of the panels. I was hoping that I could receive some help in doing so.

 

I did try to use sidebar/ merged legend after each of the overlay, but it doesnt seem to work well.

 

Thanks in advance.

 

Code:

proc template;
define statgraph line;

begingraph / designwidth=12.5 in designheight=6in ;
entrytitle ' ';
layout lattice /rowdatarange=union rows=1 columns=2 columnweights=(0.50 0.50) rowweights=(1);
*--------------------------------------------------------------------*
| Left Line Plot
*--------------------------------------------------------------------*;
layout overlay / yaxisopts=(label="&ylabelu" linearopts=(viewmin=&yminu viewmax=&ymaxu tickvaluelist=(&yvalsu)))
xaxisopts=( label="&xlabelu"
linearopts=(viewmin=0 viewmax=&xamax tickvaluesequence=(start=0 end=&xend increment=&xint)));


scatterplot x=&xvar y=&stat.u/ group=treat name='treat' markerattrs=(size=5pt);
seriesplot x=&xvar y=&stat.u /group=treat name='treatl' lineattrs=(thickness=1 );


endlayout;

*--------------------------------------------------------------------*
| Right Line Plot
*--------------------------------------------------------------------*;

layout overlay / yaxisopts=(label="&ylabell" linearopts=(viewmin=&yminl viewmax=&ymaxl tickvaluelist=(&yvalsl)))
xaxisopts=( label="&xlabell"
linearopts=(viewmin=0 viewmax=&xamax /*tickvaluelist=(&xvals)*/ tickvaluesequence=(start=0 end=&xend increment=&xint)));

scatterplot x=&xvar y=&stat.l/ group=treat name='treatl' markerattrs=(size=5pt);
seriesplot x=&xvar y=&stat.l /group=treat name='treatl' lineattrs=(thickness=1 );


endlayout;

sidebar / align=bottom;
mergedlegend "treat" "treatl" / border=off valueattrs=(size=8.75pt) order=rowmajor;
endsidebar;
endlayout;

endgraph;
end;
run;


ods _all_ close;
ods proclabel=' ';

ods rtf file="&foutput/&outputname..rtf" style=mystyle nogfootnote nogtitle bodytitle toc_data headery=720 footery=720;
ods pdf file="&foutput/&outputname..pdf" style=mystyle;
proc sgrender data=final template=line ;
run;

 

3 REPLIES 3
DanH_sas
SAS Super FREQ

In this case, there is no advantage to using separate SCATTERPLOT and SERIESPLOT statements. Try doing the following:

1. Move your MARKERATTRS options to the SERIESPLOT statements

2. Add DISPLAY=(markers) to the SERIESPLOT statements

3. Remove the SCATTERPLOT statements

4. Make sure the NAMEs on the SERIESPLOT statement are unique.

5. Change MERGELEGEND to DISCRETELEGEND and make sure the names match the names on the SERIESPLOT statements.

 

Hope this helps!

Dan

DinoPut
Obsidian | Level 7
Thank you for your response, Dan! Discretelegend could be used to display legends in both panels. Could mergedlegend be used in any way? I don't think globallegend would work either
DanH_sas
SAS Super FREQ

Oh, you want a legend in each panel. There are couple of ways to do this:

 

1. Using your ORIGINAL code, make the NAMEs on each of your series and scatter plot unique. Then, put a MERGELEGEND inside each LAYOUT OVERLAY, referencing the correct plot names in your cell.

2. You could do the steps in my previous post, and put DISCRETELEGENDs in each cell. referencing the correct series plot..

 

Be sure to remove the SIDEBAR in either case. Also, GLOBALLEGEND could be used, but I think you'll get better alignment with #1 or #2 above.

 

Hope this helps!
Dan

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 1046 views
  • 2 likes
  • 2 in conversation