Chapter Contents

Previous

Next
SAS/AF Software: Class Dictionary

Using a Color Variable in a Scatter Control

The default color is cyan for

You can use the markerColor attribute to assign a different color to all of the markers or to the entire plot surface.

To make color a response variable in the plot, you can specify a numeric variable whose values are indexed into the defined color range to determine the colors to use in the plot.

To assign the color variable, use the colorVariable attribute. The colors can represent the Sum, Mean, or Frequency statistic for the dependent variables. To specify the statistic represented by the color variable, use the colorVariableStatistic attribute.

For a Scatter control named scatter1, the following code sets the colorVariable to Sales and the colorVariableStatistic to Sum:

scatter1.colorVariable = 'sales';
scatter1.colorVariableStatistic = 'sum';

The way that the color is applied to the plot depends on the type of plot (Scatter or Surface), the values of the color variable, and the number of colors that are loaded.

By default, a scatter plot loads 16 distinct colors. The colors are distinct so that you can easily tell that one color-variable value is different from another:

[IMAGE]

By default, a surface plot loads 32 blended colors that range from yellow to red. The colors are blended to improve the surface's appearance:

[IMAGE]

To change the default color values that represent a color variable's values, you can define an alternative color range in either of two ways:


Creating a Color List in a Scatter Control

To supply your own color list of up to 64 colors:

In build mode, you can define a color list by selecting the colorList attribute, and then selecting the button that appears in the Value column. This opens the List Editor so that you can define the list of colors.

To define a color list in SCL code, make an SCL list, populate it with the list of color values, and then assign the list to the control's colorList attribute. Your code might resemble the following for a control named scatter1:

/* Make the list */
clist = makelist(3);
rc = setitemc(clist,'Red',1);
rc = setitemc(clist,'Yellow',2);
rc = setitemc(clist,'Green',3);

/* varName is the color variable's name */
scatter1.colorVariable='varName';
scatter1.colorList=clist;

The colors in your specified list are distributed evenly across the range of values in the color variable. Thus, if you define three colors in the list, only three marker colors are used. The first color in the list represents the lowest third of the color variable's values, the second color in the list represents the middle third of the color variable's values, and the third color represents the highest third:

[IMAGE]

You can also create a list of blended colors, which are particularly useful for surface plots. The following code creates a color series that ranges from red to blue:

rcolor= ' ';
gcolor = ' ';
bcolor = ' ';
r = 255;
g = 0;
b = 0;
fmt = 'hex2.';
clist = makelist(16);
do i = 1 to 16;
  rcolor = putn(r,fmt);
  gcolor = putn(g, fmt);
  bcolor = putn(b, fmt);
  cval = 'CX' || rcolor || gcolor || bcolor;
  retc = setitemc(clist,cval,i);
  r = r - 14;
  b = b + 14;
end;

/* varName is the color variable's name */
scatter1.colorVariable='varName';
scatter1.colorList=clist;

Again, colors in the list are distributed evenly across the range of values in the color variable:

[IMAGE]

To return to using the default colors, assign an empty list to the colorList attribute:

clist = makelist();
/* varName is the color variable's name */
scatter1.colorVariable='varName';
scatter1.colorList=clist;


Using a Range Entry in a Scatter Control

You can use a Range entry as the color source for a Scatter control. A Range entry is a catalog entry of type RANGE. The entry defines a range having up to 24 segments, each of which is assigned a numeric range, a color, and an attribute. For example, segment 1 might be assigned the numeric range from 0 to 5, the color Blue, and the attibute Blinking; segment 2 might be assigned the numeric range from 6 to 10, the color Green, and the attribute Highlight; and so on. A Scatter control supports the numeric ranges and the colors assigned to the segments, but it does not support the attributes (Blinking, Highlight, Reverse, Underline, and Hirev).

When used with a Scatter control, the numeric ranges that are defined in the Range entry's segments are indexed into the values of the color variable that is assigned to the Scatter control. So, using the segments defined above, the values from 0 to 5 in the color variable will be represented by Blue in the graph, and the values from 6 to 10 will be represented by Green, and so on.

To use a Range entry, you must do all of the following:

To create a Range entry, use the Range Entry window, which you can open from the SAS command line. If you need help defining the segments, use the window's Help button to get help. The following command opens the Range Entry window to create a temporary Range entry in the WORK library:

build work.color.myrange.range

After creating the Range entry, you can use its color definitions as the color source in a Scatter control. For example, if you used the command above to create a Range entry, the following code applies that entry's colors to a Scatter control named scatter1:

/* varName is the color variable's name */
scatter1.colorVariable='varName';
scatter1.colorSource='ColorRangeObject';
scatter1.colorRangeObject='work.color.myrange.range';


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.