A range attribute map enables you to
map one or more colors to a range of values of a specific numeric
column in a plot data set. It is typically used to visually highlight
ranges using single colors or a color ramp.
Note: A RANGEATTRMAP can be used
with a numeric column only.
To create and use a discrete attribute map, you must
do the following:
-
Use a RANGEATTRMAP block with one
or more RANGE statements to define your range attribute map. Use the
RANGE statement RANGECOLOR= or RANGECOLORMODEL= option to specify
a color or color ramp for each range.
-
Use a RANGEATTRVAR statement to
create an attribute variable that associates your range attribute
map with a numeric data column in your plot data set.
-
Set the MARKERCOLORGRADIENT= or
COLORRESPONSE= option in your plot statement to the name of the attribute
variable that you created in your RANGEATTRVAR statement.
The RANGEATTRMAP
block includes one or more RANGE statements that associate a range
of values with a single color or a color ramp. The syntax of the RANGE
statement is as follows:
RANGE low-value< < > – < < >high-value / options
The
optional exclusion operator (<) can be placed after the
low-value value or before the
high-value value to exclude that value from the
range endpoint. The
low-value and
high-value values can
be an unformatted numeric value or a range keyword. For
low-value, keyword MIN, NEGMAX, or NEGMAXABS
can be used instead of numeric value. For
high-value, keyword MAX or MAXABS can be used. For information about the range
keywords, see
SAS Graph Template Language: Reference.
Note: If two ranges share a common
endpoint, such as 10–20 and 20–30, and no exclusion
operator ( < ) is used, the common endpoint belongs to the lower
range, which is 10–20 in this case.
The RANGEATTRMAP statement
also includes a NAME= option that enables you to specify a unique
name for the range attribute map. The RANGEATTRMAP block must appear
in the global definition area of the template between the BEGINGRAPH
statement and the first LAYOUT statement. It cannot be nested within
any other statement. An ENDRANGEATTRMAP statement is required to end
the block. The block must contain at least one RANGE statement.
The RANGEATTRVAR statement creates a named association
between a range attribute map and a numeric column in your plot data
set. To create the range attribute variable, do the following in your
RANGEATTRVAR statement:
-
Add a RANGEATTRVAR statement to
the global definition area of your template between the BEGINGRAPH
statement and the first layout statement.
-
In the RANGEATTRVAR statement:
-
Set the ATTRVAR= option to a unique
name for range attribute map to data set column association.
-
Set the ATTRMAP= option to the
value of the NAME= option that you used in your RANGEATTRMAP statement.
-
Set the VAR= option to the name
of the numeric column in your plot data set with which the range attribute
map is to be associated.
After your create the
range attribute map and the range attribute variable, in your plot
statement, set the value of the option that maps the column values
to colors to the name that you specified with the ATTRMAP= option
in your RANGEATTRVAR statement.
Note: The values and graphical
attributes defined in a range attribute map cannot be displayed by
a DISCRETELEGEND statement.
Here is an example of
a template that creates and applies a range attribute map to the WEIGHT
column of a SCATTERPLOT statement data set in order to color the markers
in the resulting plot by weight range. It also creates a continuous
legend.
proc template;
define statgraph attrrange;
begingraph;
/* Create the range attribute map. */
rangeattrmap name="scale";
range 0-70 /
rangecolormodel=(black); /* 0 to 70 inclusive */
range 70<-107 /
rangecolormodel=(blue); /* 70 exclusive to 107 inclusive */
range 107<-125 /
rangecolormodel=(green); /* 107 exclusive to 125 inclusive */
range 125<-200 /
rangecolormodel=(red); /* 125 exclusive to 200 inclusive */
endrangeattrmap;
/* Create the range attribute variable. */
rangeattrvar attrvar=weightrange var=weight attrmap="scale";
/* Create the graph. */
entrytitle "Weight Class";
layout overlay /
xaxisopts=(griddisplay=on gridattrs=(color=lightgray pattern=dot))
yaxisopts=(griddisplay=on gridattrs=(color=lightgray pattern=dot));
scatterplot x=weight y=height / markercolorgradient=weightrange
markerattrs=(symbol=circlefilled size=10) name='wgtclass';
/* Add a continuous legend. */
continuouslegend 'wgtclass';
endlayout;
endgraph;
end;
run;
/* Render the graph. */
ods graphics / width=4in height=3in;
proc sgrender data=sashelp.class template=attrrange;
run;
The following figure
shows the resulting output.
In the example code,
notice that the NAME=”scale” option in the RANGEATTRMAP
statement provides a name for the range attribute map. Also notice
that the ATTRVAR=weightrange option in the RANGEATTRVAR statement
provides a name for the attribute-map-to-data-set-column association.
The ATTRMAP=”scale” and the VAR=weight options in the
RANGEATTRVAR statement associate the attribute map scale with the
data set column WEIGHT respectively. In the SCATTERPLOT statement,
the MARKERCOLORGRADIENT=weightrange option applies the range attribute
map to the WEIGHT column variable values and colors the plot markers
according to the ranges that are specified in the range attribute
map. To add a legend that displays the marker colors for the weight
ranges, you can include a CONTINUOUSLEGEND statement.
For information about
continuous legends, see Features of Continuous Legends.