Changing the Color and Shape of Observation Markers |
The ColorCodeObs and ColorCodeObsByGroups modules color observations by calling the SetMarkerColor method of the DataObject class. While these module are often convenient to use, sometimes you might want to color markers according to some criterion that is not covered by either module. In this case, you can use the SetMarkerColor method directly.
The SetMarkerColor method changes the colors of specified observations. It is usually used in conjunction with the GetVarData method of the DataObject and the IML LOC function to find observations that satisfy some criterion.
As an example, suppose you are interested in the size of the eye of a tropical cyclone. (The eye of a cyclone is a calm, relatively cloudless central region.) The Hurricanes data set has a variable radius_eye that gives the radius of the cyclone's eye in nautical miles. The radius_eye variable has many missing values, because not all storms have well-defined eyes. You can use the SetMarkerColor method to visualize the observations for which well-defined eyes exist.
Add the following statements at the bottom of the program window and select Program Run from the main menu.
/* color markers manually */ dobj.SetMarkerColor( OBS_ALL, BLACK ); dobj.GetVarData("radius_eye", rEye ); idx = loc( rEye = . ); if ncol(idx)>0 then dobj.SetMarkerColor( idx, GREEN );
Figure 10.3: Markers Colored Manually
The first statement uses the special keyword OBS_ALL
to set the color
of all observations in the data set to black. The GetVarData method
of the DataObject copies the values of the radius_eye
variable into an IML matrix called rEye. The IML 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 SetMarkerColor method sets the color of
corresponding observations to green.
You can see from the resulting graph (Figure 10.3) that very few storms with low wind speeds have well-defined eyes, whereas most of the intense storms have well-defined eyes.
Of course, you could repeat this process for other conditions you want to visualize. For example, you could locate the values of rEye that are greater than or equal to 20 nautical miles, and color those observations.
Copyright © 2008 by SAS Institute Inc., Cary, NC, USA. All rights reserved.