Data visualization with SAS programming

Super impose two common discretelegend with slidebar

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

Super impose two common discretelegend with slidebar

I am using following code. i wanted legend as in the attached figure but i am getting two different leagends separately. How can i get desired legend? I am using SAS 9.3.

legend.PNGDesired legend.

 

proc means data=sashelp.class nway noprint;
    class sex age;
    var weight;
    output out=_td_mean 
                mean=mean
                lclm=low
                uclm=high;
run;

proc template;
    define statgraph highlow;
        begingraph;
            layout datapanel classvars=(sex)/columns=2
                                             columngutter=5
                                             headerlabeldisplay=value
                                             headerlabelattrs=(weight=bold)
                                             headerbackgroundcolor=lightgray
                                             columnaxisopts=(display=(label tickvalues ticks line)
                                                             label=("Age (Years)") labelattrs=(weight=bold)
                                                             linearopts=(tickvaluepriority=true tickvaluelist=(1 2 3 6 9 12)))
                                             rowaxisopts=(display=(label tickvalues ticks line)
                                                          label=("Mean Weight (kgs)") labelattrs=(weight=bold))
                                             ;
                layout prototype;
                    seriesplot x=age y=mean/group=trt01p lineattrs=(pattern=solid) name='p';
                    scatterplot x=age y=mean/group=trt01p
                             yerrorlower=low
                             yerrorupper=high
                             markerattrs=(symbol=circlefilled) name='s';
                    referenceline y=50 / LINEATTRS = (PATTERN = DOT);
                    referenceline y=150 / LINEATTRS = (PATTERN = DOT);
                endlayout;
                sidebar / align=bottom; 
                    discretelegend "s" "p" / border=false;
                  endsidebar;

            endlayout;
        endgraph;
    end;
run;
ods graphics on/noborder;
proc sgrender data=_td_mean template=highlow;
run;
ods graphics off;

 

 


Accepted Solutions
Solution
‎09-25-2015 06:23 AM
SAS Super FREQ
Posts: 1,081

Re: Super impose two common discretelegend with slidebar

Use MERGEDLEGEND.

 

proc template;
  define statgraph mergedLegend;
    begingraph;
      Layout overlay;
        scatterplot x=age y=height / group=sex name='scatter';
        seriesplot x=age y=height / group=sex name='series' connectorder=xaxis;
        mergedlegend 'scatter' 'series';
      endlayout;
    endgraph;
  end;
run;

proc sgrender data=sashelp.class template=mergedLegend;
run;

View solution in original post


All Replies
Grand Advisor
Posts: 10,241

Re: Super impose two common discretelegend with slidebar

Using 9.2 I get a single legend across the bottom. Adding Across=1 gets me a stacked legend at the bottom.

 

 

Contributor
Posts: 20

Re: Super impose two common discretelegend with slidebar

legend.PNG

 

Thanks.  I tried that as well. I am getting like above.

Grand Advisor
Posts: 10,241

Re: Super impose two common discretelegend with slidebar

That sounds like the desired output. If you need different text then the LEGENDLABEL needs to be set for each of the plots.

The color and marker symbols would have to be set with the appropriate attributes for the plot.

 

Solution
‎09-25-2015 06:23 AM
SAS Super FREQ
Posts: 1,081

Re: Super impose two common discretelegend with slidebar

Use MERGEDLEGEND.

 

proc template;
  define statgraph mergedLegend;
    begingraph;
      Layout overlay;
        scatterplot x=age y=height / group=sex name='scatter';
        seriesplot x=age y=height / group=sex name='series' connectorder=xaxis;
        mergedlegend 'scatter' 'series';
      endlayout;
    endgraph;
  end;
run;

proc sgrender data=sashelp.class template=mergedLegend;
run;

Contributor
Posts: 20

Re: Super impose two common discretelegend with slidebar

Thank you very much Sanjay.

I choose GTL option. Since uneven axis values not working for SGPANEL with colaxis/rowaxis but working for SGPLOT with xaxis-yaxis. I also commented your post http://blogs.sas.com/content/graphicallyspeaking/2012/04/30/axis-values-and-hint/
☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 409 views
  • 1 like
  • 3 in conversation