SAS Institute. The Power to Know

SAS/GRAPH(R) 9.2: Graph Template Language Reference

Previous | Next
Overview

Legends

Many plot statements support a GROUP= option that partitions the data into unique values, performs separate analysis, if necessary, and automatically assigns distinct visual properties to each group value. The visual properties of group values are defined by the style in effect.

In the follwoing example, a legend is added to associate group values with markers and line patterns from the scatter plot and linear regression lines. Note that a name is assigned to each plot. These names are used as arguments for the DISCRETELEGEND statement.

  
 proc template; 
  define statgraph scatterfit; 
   begingraph; 
   entrytitle "Linear Regression By Gender"; 
    layout overlay; 
      scatterplot x=height y=weight / group=sex name="scat"; 
      regressionplot x=height y=weight/ group=sex name="reg"; 
      discretelegend "scat" "reg" / border=true; 
    endlayout; 
   endgraph; 
  end; 
 run;
 
ovlgndgrp.gif (40490 bytes)


Sometimes you would like a legend in the graph when there is no grouping. The plot's LEGENDLABEL= option specifies the legend entry text for each legend contributor. The legend representations automatically match the visual properties of the contributors.

  
 proc template; 
  define statgraph scatterfit2; 
   begingraph; 
   entrytitle "Linear Regression"; 
    layout overlay; 
      modelband "pred" / name="band1" display=(outline) 
          legendlabel="95% Prediction Limits"; 
      modelband "conf" / name="band2" display=(fill) 
          legendlabel="95% Confidence Limits"; 
      scatterplot x=height y=weight; 
      regressionplot x=height y=weight / name="line" 
          alpha=.05 cli="pred" clm="conf" legendlabel="Fit"; 
      discretelegend  "line" "band1" "band2" / 
          across=1 border=true; 
    endlayout; 
   endgraph; 
  end; 
 run;
 
ovlgndnogrp.gif (51830 bytes)


Some plot statements enable you to define a continuous response variable that is mapped to a color range. A CONTINUOUSLEGEND statement is used to display the colors that are associated with response values. Note that the COLORMODEL= option of the contour specifies which style element to use for the color ramp. Several two- and three-color ramps are available in each style element.

  
 proc template; 
  define statgraph contour; 
   begingraph; 
    entrytitle "Bivariate KDE for X and Y"; 
    layout overlay; 
     contourplotparm x=x y=y z=density / name="cont" 
         contourtype=gradient 
         colormodel=ThreeColorLowHigh; 
     continuouslegend "cont" / pad=(left=8) 
         title="Density"; 
    endlayout; 
   endgraph; 
  end; 
 run;
 
ovlgndcont.gif (57498 bytes)


Previous | Next | Top of Page