Previous Page | Next Page

Changing the Color and Shape of Observation Markers

Change Marker Shapes

When a graph is printed on a gray-scale printer, it is often easier to discern observations that have different marker shapes than it is to discern markers of different colors. Even on a computer screen, marker shape is sometimes preferred for classifying markers according to a small number of discrete values. For example, if some observations represent males and others females, marker shape is an ideal way to encode that information.

Just as you can change marker colors with the SetMarkerColor method, you can change a marker’s shape with the DataObject’s SetMarkerShape method. For the Hurricanes data set, suppose you want to use marker shape to differentiate observations with missing values for the radius_eye variable from those with nonmissing values. One way to accomplish this is to copy the values of radius_eye from the DataObject, and then use the LOC function to find the observation numbers with certain properties. You can then use the SetMarkerShape method to set the shape of the observations.

Add the following statements at the bottom of the program window, and select Program Run from the main menu. Figure 10.4 shows the result of running these statements.

   /* change marker shapes */
   dobj.GetVarData("radius_eye", rEye );
   idx = loc( rEye = . );
   if ncol(idx)>0 then
      dobj.SetMarkerShape( idx, MARKER_X );
   idx = loc( rEye ^= . );
   if ncol(idx)>0 then
      dobj.SetMarkerShape( idx, MARKER_CIRCLE );
   plot.SetMarkerSize( 6 );
   dobj.SetMarkerFillColor( OBS_ALL, NOCOLOR );

When you run these statements, the GetVarData method of the DataObject copies the values of the radius_eye variable into a SAS/IML matrix called rEye. The LOC function is then used to find the indices of missing values in the rEye matrix. If at least one element of the matrix satisfies the condition, then the SetMarkerShape method sets the shape of corresponding observations to an "." The shape of markers for observations with nonmissing values is set to a circle.

Note:It is a good programming practice to verify that the LOC statement did not return an empty matrix.

The SetMarkerSize method changes the marker sizes on a scale from 1 (the smallest) to 8 (the largest). This method is in the Plot class, so changing the size of markers in one graph does not change the size of markers in other graphs. (This is in contrast to the DataObject methods, which set the shape and color for all graphs that display an observation.) Finally, the SetMarkerFillColor method is used to make all markers hollow. Hollow markers can sometimes help reduce overplotting in scatter plots.

Figure 10.4 Changing Marker Shapes
Changing Marker Shapes

In this example you used the MARKER_X and MARKER_CIRCLE shapes. The complete list of valid SAS/IML Studio marker shapes is given in Table 10.2.

Table 10.2 Marker Shapes









Previous Page | Next Page | Top of Page