Examples


Example 1: Generating a Simple Contour Plot

Procedure features:

  • PLOT statement

Other features:

  • FORMAT statement

  • G3GRID procedure

Sample library member: GCTCLAY1

click to expand

This example shows a simple contour plot that describes the percentage of clay found in soil samples at various locations of a testing site. By default, the axes are scaled to include all data values and are labeled with the names of the axes variables . Values are plotted with seven contour levels, which are represented by contour lines with default colors and line types. The default contour levels occur at every 15th percent of the range between the contour variable s 5th and 95th percentile. The legend is labeled with the contour variable s name and identifies the contour levels that are included in the plot.

This example uses the G3GRID procedure to interpolate clay percentages for grid cells that do not have percentages in the data. Without the G3GRID procedure, there are too many missing values for the percentages, and the GCONTOUR procedure cannot produce a satisfactory contour plot.

Assign the libref and set the graphics environment.

 libname reflib '  SAS-data-library  ';  goptions reset=global gunit=pct border cback=white           colors=(black blue green red)           ftext=swiss ftitle=swissb htitle=6 htext=4; 

Create the data set. REFLIB.CLAY contains the percent of clay at various locations of a test site.

 data reflib.clay;     input x y pct_clay;     datalines;  -10    -10       2.316  -10     -9       1.816  -10     -8       2.427  ...more data lines...  10      8        .   10      9        .   10     10        .  ; 

Interpolate values for the contour plot. The interpolated data set is stored in REFLIB.CLAY2.

 proc g3grid data=reflib.clay out=reflib.clay2;     grid y*x=pct_clay / naxis1=21                         naxis2=21                         join;  run; 

Define title and footnote.

 title1 'Clay Content at Site A';  footnote1 j=r ' GCTCLAY1 '; 

Generate a simple contour plot. The procedure uses REFLIB.CLAY2, the output data set from PROC G3GRID. To simplify the legend labels, clay percentages are formatted with no decimal positions .

 proc gcontour data=reflib.clay2;     format pct_clay 2.0;     plot y*x=pct_clay;  run;  quit; 

Example 2: Labeling Contour Lines

Procedure features:

  • PLOT statement options:

    • AUTOLABEL=

    • HAXIS=

    • LEGEND=

    • LEVELS=

    • VAXIS=

Other features:

  • AXIS statement

  • LEGEND statement

  • SYMBOL statement

Data set: REFLIB.CLAY2

Sample library member: GCTCLAY2

click to expand
Display 30.2: A Simple Contour Plot with Labelled Contour Levels

This example modifies Example 1 on page 904 to label contour levels with the AUTOLABEL option. When AUTOLABEL is used, the SYMBOL statement controls the labels and attributes of contour lines. In this example, SYMBOL1 defines a text label for the lowest contour level. Each remaining contour line gets the default label, which is the contour variable s value at that contour level. All the contour lines are solid, which is the default line type for the SYMBOL statement.

This example also uses AXIS statements to limit the plot to one of the contour areas from the output of Example 1 on page 904, and it uses a LEGEND statement to move the legend so the procedure has more room for displaying the y axis.

Assign the libref and set the graphics environment.

 libname reflib '  SAS-data-library  ';  goptions reset=global gunit=pct border cback=white           colors=(black blue green red)           ftext=swiss ftitle=swissb htitle=6 htext=4; 

Define title and footnote.

 title1 'Clay Content at Site A';  footnote1 j=r 'GCTCLAY2'; 

Define axes characteristics. AXIS1 uses ORDER= to set major tick marks at 2-unit intervals from -10 to -4. AXIS2 uses ORDER= to specify 2-unit intervals from -10 to 2. These axes ranges effectively zoom in on one of the contour areas from Example 1 on page 904.

 axis1 order=(-10 to -4 by 2);  axis2 order=(-10 to 2 by 2); 

Define legend characteristics. POSITION= centers the legend to the right of the graphics area, and LABEL= positions the legend label above the legend entries. ACROSS= places legend entries in rows 1 entry wide.

 legend1 position=(right middle)          label=(position=top)          across=1; 

Define symbol characteristics. SYMBOL1 specifies a font and text string to label the lowest-level contour lines. COLOR = ensures that each SYMBOL definition is used only once. In SYMBOL2, STEP= increases the number of contour labels by placing the labels closer together than the default distance of 65 percent.

 symbol1 height=2.5          font=swissb          value='lowest'          color=red;  symbol2 height=2.5          step=25pct          color=black;  symbol3 height=2.5          color=blue;  symbol4 height=2.5          color=green; 

Generate the contour plot. LEVELS= specifies contour levels from 10 to 90 at 20-unit intervals. AUTOLABEL= turns on labeling, and CHECK=NONE turns off collision checking so the maximum number of contour labels can be displayed. HAXIS= and VAXIS= assign AXIS definitions to the plot. LEGEND= assigns the LEGEND1 definition to the plot.

 proc gcontour data=reflib.clay2;     plot y*x=pct_clay / levels=10 to 90 by 2 0                         autolabel=(check=none)                         haxis=axis1                         vaxis=axis2                         legend=legend1;  run;  quit; 

Example 3: Specifying Contour Levels

Procedure features:

  • PLOT statement options:

    • LEVELS=

    • LLEVELS=

Sample library member: GCTPOND

click to expand
Display 30.3: A Contour Plot Generated with Specific Contour Levels

This example generates a contour plot that shows the height or depth of a pond and its surrounding land. In the example, the PLOT statement uses the LEVELS= and LLEVELS= options to specify explicit contour levels and line types for the contour plot. It also uses a LEGEND statement to modify the plot's default legend.

This example uses the G3GRID procedure to interpolate points for grid cells that do not have a needed dimension in the data. Without the G3GRID procedure, there are too many missing values for the point locations, and the GCONTOUR procedure cannot produce a satisfactory contour plot.

Assign the libref and set the graphics environment.

 libname reflib '  SAS-data-library  ';  goptions reset=global gunit=pct border cback=white           colors=(black blue green red)           ftext=swiss ftitle=swissb htitle=6 htext=3; 

Create the data set. REFLIB.POND contains the raw data for a pond floor and surrounding land.

 data reflib.pond;     input vdist hdist height;     datalines;  10    88       0  18    55      -1  24    22.5    -1.67  ...more data lines...  64    272.5  -6.25  60    277.5  -6.5  62    277.5  -6.5  ; 

Define title and footnote.

 title 'Bottom Contour of Mill Pond';  footnote j=r ' GCTPOND '; 

Define axis characteristics.

 axis1 order=(0 to 325 by 25) width=3 minor=(n=4)        label=('Feet');  axis2 order=(0 to 100 by 25) width=3 minor=(n=4)        label=(' Feet'); 

Define legend characteristics.

 legend1 frame shape=line(7)          label=(position=top j=c 'Height or Depth (in feet)'); 

Interpolate points for the contour plot.

 proc g3grid data=reflib.pond out=reflib.pondgrid;     grid vdist*hdist=height / naxis1=100 naxis2=100;  run; 

Generate the contour plot. LEVELS= specifies the values of the contour levels. LLEVELS= sets the line types for the contour lines. Solid lines identify negative contour levels, and dashed lines identify positive contour levels.

 proc gcontour data=reflib.pondgrid;     plot vdist*hdist=height /levels= -30 -12 -7 -3 0 3 5 7 12                              llevels=  1   1  1 1  1 2 2 2 2  2                              legend=legend1                              haxis=axis1                              vaxis=axis2;  run;  quit; 

Example 4: Using Patterns and Joins

Procedure features:

  • PLOT statement options:

    • COUTLINE=

    • CTEXT=

    • JOIN

    • PATTERN

Sample library member: GCTPATRN

click to expand
Display 30.4: A Contour Plot that uses Contour Lines

This example demonstrates the differences between using lines and patterns to represent contour levels. It first uses a simple PLOT statement to generate the default output, which uses lines to represent contour levels.

As shown in the following output, the example then modifies the PLOT statement by specifying the PATTERN option, which uses patterns to distinguish between contour levels. Additional PLOT statement options outline filled areas in gray and specify green text for all text on the axes and in the legend.

click to expand
Display 30.5: A Contour Plot that uses Patterns

Finally, as shown by the following output, the example uses the JOIN option to combine the patterns in grid cells for the same contour level. Additional options enhance the plot by modifying the axes and framing the legend.

click to expand
Display 30.6: A Contour Plot with Joined Cells

Assign the libref and set the graphics environment.

 libname reflib '  SAS-data-library  ';  goptions reset=global gunit=pct border cback=white           colors=(black blue green red)           ftext=swiss ftitle=swissb htitle=6 htext=4; 

Create the data set. REFLIB.SWIRL is generated data that produces a symmetric contour pattern, which is useful for illustrating the PATTERN option.

 data reflib.swirl;     do x= -5 to 5 by 0.25;        do y= -5 to 5 by 0.25;           if x+y=0 then z=0;           else z=(x*y)*((x*x-y*y)/(x*x+y*y));           output;        end;     end;  run; 

Define title and footnote for the default output.

 title 'Simple Contour Plot';  footnote j=r 'GCTPATR1 '; 

Generate a simple contour plot.

 proc gcontour data=reflib.swirl;     plot y*x=z;  run; 

Define title and footnote for second plot.

 title 'Representing Contour Levels with Patterns';  footnote j=r 'GCTPATR2 '; 

Generate the contour plot. PATTERN fills the contour levels with solid patterns. COUTLINE= names the color that outlines the grid cells. CTEXT= names a color for axes and legend text.

 proc gcontour data=reflib.swirl;     plot y*x=z / pattern                  coutline=gray                  ctext=green;  run; 

Define title and footnote for last plot.

 title 'Joining the Patterns in a Contour Plot';  footnote j=r 'GCTPATR3 '; 

Define axis and legend characteristics for last plot. Blanks are used to suppress tick labels at positions -2.5 and 2.5.

 axis1 label=none value=('' ' ' '0' ' ' '5')        color=red width=3;  axis2 label=none value=('' ' ' '0' ' ' '5')        color=red width=3;  legend frame; 

Generate the last contour plot. JOIN combines grid cells for the same contour levels.

 proc gcontour data=reflib.swirl;     plot y*x=z / pattern                  join                  haxis=axis1                  vaxis=axis2                  legend=legend1;  run;  quit; 



SAS.GRAPH 9.1 Reference, Volumes I and II
SAS.GRAPH 9.1 Reference, Volumes I and II
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 342

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net