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;
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
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
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!
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.
Ready to level-up your skills? Choose your own adventure.