equate Create AXIS statements for a GPLOT with equated axes equate

Visualizing Categorical Data: equate

$Version: 1.2 (10 Dec 1999)
Michael Friendly
York University

The equate macro ( [download] get equate.sas)

Create AXIS statements for a GPLOT with equated axes

The EQUATE macro creates AXIS statements for a GPLOT with equated axes, and optionally produces a plot using point labels (supplied in an input annotate data set). It is used as a utility macro to create plots where angles between vectors and distances between points have meaning, so the axes should be scaled to the same physical units.

For the vertical axis variable Y it creates (by default) an AXIS98 statement and for horizontal axis variable X it creates an AXIS99 statement. These use the ORDER= and LENGTH= parameters to ensure that an inch on the vertical axis represents the same data range as an inch on the horizontal axis.

Method

If the tick mark increments XINC= and YINC= are not specified, the EQUATE macro uses the range of the X= and Y= variables to calculate reasonable increments (nice numbers, with a leading digit of 1, 2, 2.5, 4, or 5) to give about 6 tick marks on the horizontal and vertical scales.

If the maximum plot dimensions XMAX= and YMAX= are not specified, the EQUATE macro uses the GASK call to obtain the maximum values from the device driver.

Usage

The EQUATE macro takes 15 keyword arguments. The X= and Y= parameters are required. The arguments may be listed within parentheses in any order, separated by commas. For example:
   %equate(data=inputdataset, X=xvar, Y=yvar, ..., )

Reset the defaults below to be more suited to your devices. As well, use GOPTIONS HSIZE= VSIZE=; to allow the maximum plot size if you do not specify the XMAX and YMAX parameters.

Parameters

Default values are shown after the name of each parameter.
DATA=_last_
Name of the input data set
ANNO=&data
Name of the input Annotate data set (if PLOT=YES)
X=x
Name of the X variable.
Y=y
Name of the Y variable.
XMAX=6.5
Maximum Y axis length (inches).
YMAX=8.5
Maximum Y axis length (inches).
XINC=0.1
X axis tick increment.
YINC=0.1
Y axis tick increment.
XPEXTRA=0
Number of extra tick marks at + end of X axis. Use the EXTRA parameters to extend the range of the plot beyond the minima/maxima to accommodate long point labels.
XMEXTRA=0
Number of extra tick marks at - end of X axis.
YPEXTRA=0
Number of extra tick marks at + end of Y axis.
YMEXTRA=0
Number of extra tick marks at - end of Y axis.
VAXIS=axis98
AXIS statement generated for Y axis.
HAXIS=axis99
AXIS statement generated for X axis.
PLOT=NO
Draw the plot if PLOT=YES.

Example

This example uses the CORRESP macro to analyze data on repeat victimization, where the rows refer to the first crime, and variables refer to the second. In order to show the changes in position (first --> second), we use CORRESP to calculate the positions of row and column points, but suppress the default plot, and create a customized plot with equated axes shown below.
%include vcd(equate);        *-- or include in an autocall library;
%include vcd(corresp);       *-- or include in an autocall library;
data victims;
   input crime $ Rape Assault Robbery PickPock PLarceny
                 Burglary HLarceny AutoThft;
cards;
Rape        26   50  11   6    82   39   48   11
Assault     65 2997 238  85  2553 1083 1349  216
Robbery     12  279 197  36   459  197  221   47
PickPock     3  102  40  61   243  115  101   38
PLarceny    75 2628 413 329 12137 2658 3689  687
Burglary    52 1117 191 102  2649 3210 1973  301
Hlarceny    42 1251 206 117  3757 1962 4646  391
AutoThft     3  221  51  24   678  301  367  269
;
%corresp(data=victims, id=crime,
   var=Rape Assault Robbery PickPock PLarceny Burglary HLarceny AutoThft,
   pos=8, gplot=NO, anno=labels);
An Annotate data set LINES is then created to draw the lines, and is appended to the ANNO=LABELS
*-- Sort crimes by upcase(_name);
data coord;
   set coord;
   _name_ = upcase(_name_);
proc sort data=coord;
   where (_type_ ^= 'INERTIA');
   by _name_ _type_;

*-- Join first/second occurrence;
data lines;
   set coord(keep=_name_ _type_ dim1 dim2);
   by _name_ _type_;
   xsys='2'; ysys='2';
   x = dim1; y = dim2;
   if first._name_
      then function='MOVE';
      else function='DRAW';

*-- Remove _type_='VAR' labels, and add lines;
data label;
   set label(where=(_type_^='VAR')) lines;
Finally, we generate AXIS statements using EQUATE, and produce the plot
%equate(data=coord, x=dim1, y=dim2, plot=no, vaxis=axis98, haxis=axis99,
      xmextra=1, ymextra=1);

proc gplot data=coord;
   plot dim2 * dim1 = _type_
        / anno=label frame legend=legend1
          vaxis=axis98 haxis=axis99 vminor=1 hminor=1;
   symbol1 h=1.2 v=dot    c=blue;
   symbol2 h=1.2 v=circle c=red;
   legend1 position=(bottom inside left)  offset=(1,2)
        mode=share cborder=blue
        across=1 shape=symbol(6,1.5)
        label=('Occurrence') value=('First' 'Second');
run;

See also

biplot Biplot display of variables and observations
corresp Correspondence analysis