Example: Create a Contour Plot

In this example you examine three variables in the Climate data set. You explore the functional relationship between the elevationFeet variable and the latitude and longitude variables. The elevationFeet variable gives the elevation in feet above mean sea level for each of 40 cities in the continental United States.

None of the variables in this example have missing values. If an observation has a missing value for any of the three variables in the contour plot, that observation is not plotted.

To create a contour plot:

  1. Open the Climate data set.

  2. Select GraphContour Plot from the main menu, as shown in Figure 7.14.

    Figure 7.14: Selecting a Contour Plot


    The Contour Plot dialog box appears. (See Figure 7.15.)

  3. Select the elevationFeet variable, and click Set Z.

  4. Select the latitude variable, and click Set Y.

  5. Select the longitude variable, and click Set X.

  6. Click OK.

    Figure 7.15: A Contour Plot Dialog Box


    A contour plot appears (Figure 7.16), which shows a scatter plot of the longitude and latitude variables. Contours of the elevationFeet variable are shown overlaid on the scatter plot.

Figure 7.16: A Contour Plot


You can double-click an observation to display the variable values that are associated with that observation. (See the section Observation Inspector for further details.) In this way, you can identify cities and find out their exact elevations.

It is somewhat difficult to guess where the state boundaries are in Figure 7.16, so Figure 7.17 overlays the outline of the continental United States onto the contour plot. The figure was created by using the DrawPolygonsByGroups module, which is documented in the SAS/IML Studio online Help chapter titled IMLPlus Module Reference.

Figure 7.17: A Contour Plot


Note: You can create a contour plot of any three continuous variables, but you should first determine whether it is appropriate to do so. Contour plots might not be appropriate for data with replicated measurements or for data with highly correlated X and Y variables.

If you display the contour plot property dialog box, you can examine the values that are associated with each contour. (To display plot properties, right-click near the center of a plot, and select Plot Area Properties from the pop-up menu.) Figure 7.18 shows that there are 10 evenly spaced contours in the range of the elevationFeet variable. The minimum and maximum values of elevationFeet are 3 and 6126.

Figure 7.18: Default Contours


Example: Change Contour Values and Appearance

The default contours are usually adequate for obtaining a qualitative feel for the response surface. However, sometimes you might want to manually specify the levels of the contours. You might need to conform to some standard (for example, 50-meter contour intervals) or include a critical level (for example, a control limit).

Suppose you decide that you want the contour levels of elevationFeet to be round numbers, such as multiples of 100. You can change the set of contours by removing the old contours, adding new contours, and coloring the new contours.

To remove the old contours:

  1. Select the first contour (labeled 3). Scroll the Contour Levels list to the last contour. Hold down the SHIFT key while clicking the last contour (labeled 5819.85) to select all contours in the list.

  2. Click Remove selected levels, as shown in Figure 7.19.

    Figure 7.19: Removing Contours


    To add a new set of uniformly spaced contours, do the following:

  3. Click the Levels subtab. (See Figure 7.20.)

  4. Type 10 in the Number field.

  5. Type 0 in the Minimum field.

    The value for this field is typically a round number near the minimum value of the Z variable.

  6. Type 6000 in the Maximum field.

    The value for this field is typically a round number near the maximum value of the Z variable.

  7. Click the large left arrow ($\Longleftarrow $) to create the contours, as shown in Figure 7.20.

    Figure 7.20: Adding Evenly Spaced Contours


    The Contour Levels list is filled with the values $300, 900, \ldots , 5700$. These values do not include the minimum and maximum specified values (0 and 6000), because contours at the extreme values are often degenerate.

    By default, the region between the new contours is gray. You can change the colors of contours by doing the following:

  8. Click the Contour Styles subtab. (See Figure 7.21.)

  9. Select a gradient color map from the Blend list.

  10. Click the large left arrow ($\Longleftarrow $) to color the selected contours according to the gradient color map, as shown in Figure 7.21.

    Figure 7.21: Coloring Contours


  11. Click Apply to update the contour plot.

    You can also add individual contours for specific levels. For example, some investigators might want to see the sea level contour, $\mbox{Z}=0$. Adding an individual contour is similar to adding a set of contours:

  12. Click the Levels subtab.

  13. Type 1 in the Number field.

  14. Type 0 in the Minimum field.

  15. Type 0 in the Maximum field.

    If the minimum and maximum values are the same, then a single contour is created at the common value.

  16. Click the large left arrow ($\Longleftarrow $) to create the contour, as shown in Figure 7.22.

    Figure 7.22: Adding a Single Contour


  17. Click OK to apply the changes.

    The contour plot looks like the plot in Figure 7.23. Note that the contour plot has not qualitatively changed from Figure 7.16. The new contour values are within a few hundred feet of their previous values, so the new contour curves are close to the previous contours. The primary change is that the new contours correspond to round numbers of elevationFeet. The colors are also slightly different.

Figure 7.23: A Plot with Custom Contours


Note: In this example you added a single contour at $\mbox{Z}=0$. While SAS/IML Studio permits you to add contours at any level of the Z variable, you should usually choose evenly spaced levels. A standard usage of contour maps is to locate regions in which the contours are densely packed. These regions correspond to places where the gradient of Z is large; that is, the function is changing rapidly in these regions. If you add contours that are not evenly spaced in the range of Z, then you risk creating contours that are close together even though the gradient of Z is not large.