Lattice-type layouts
(LAYOUT LATTICE, LAYOUT DATALATTICE, and LAYOUT DATAPANEL) present
a grid of graphs that automatically aligns plot areas and tick display
areas across grid cells. This alignment facilitates data comparisons
among graphs, and for those comparisons to be meaningful, the graph
axes must be coordinated across the columns and rows in the grid.
All of the principles discussed in
Overview for Axis Mapping apply to the lattice-type layouts. In addition, because
there can be multiple X, X2, Y, and Y2 axes across grid cells, you
might have to use layout options to specify how the data ranges and
axis display should be managed.
For example, the following
template uses a LAYOUT LATTICE to generate a grid that displays a
height analysis next to a weight analysis. By default in a LAYOUT
LATTICE statement, the options ROWDATARANGE= and ROW2DATARANGE= are
set to DATA. The DATA setting scales the Y-axis and Y2-axis data ranges
separately for each cell in the layout. To ensure that the Y-axis
data range is the same in both cells, the example specifies ROWDATARANGE=UNION.
Similarly, to ensure that the Y2-axis data range is the same in both
cells, the example specifies ROW2DATARANGE=UNION:
proc template;
define statgraph y2axis;
begingraph;
layout lattice / columns=2 columngutter=10
rowdatarange=union row2datarange=union ;
layout overlay;
histogram height / scale=count yaxis=y2;
histogram height / scale=percent yaxis=y;
densityplot height / normal();
endlayout;
layout overlay;
histogram weight / scale=count yaxis=y2;
histogram weight / scale=percent yaxis=y;
densityplot weight / normal();
endlayout;
endlayout;
endgraph;
end;
proc sgrender data=sashelp.class template=y2axis;
run;
By default in a LAYOUT
LATTICE statement, the options COLUMNDATARANGE= and COLUMN2DATARANGE=
are also set to DATA. But in this analysis, the height is a separate
measure from the weight, so the separate scales are appropriate for
the X-axes across cells. If the X-axes were displaying the same measure
(for example, comparing the height of female subjects to the height
of male subjects), you could specify COLUMNDATARANGE=UNIONALL. This
would set the same scaling to the X-axis data ranges across the two
layout columns. In this example you would not bother changing the
default COLUMN2DATARANGE= setting because the X2 axis is not needed.
Note: For DATALATTICE and DATAPANEL
statements, UNIONALL is the default value for the data ranges. Thus,
you would not have to change the data ranges unless you wanted to
set UNION to scale data ranges per row or per column in the layout.
In the example, scaling the data ranges
across the row ensures proper axis scaling. However, the graph display
is cluttered by the duplicate display of ticks, axis values, and axis
labels on both the Y and Y2 axes. To simplify the display, you can
consolidate the axes. To do so, use a ROWAXES block to display a single
Y axis for both cells, and a ROW2AXES block to display a single Y2
axis for both cells. The consolidated view removes the internal axes
from the grid and displays only the external axes:
proc template;
define statgraph y2axis;
begingraph;
layout lattice / columns=2 columngutter=10
rowdatarange=union row2datarange=union;
rowaxes;
rowaxis / griddisplay=on;
endrowaxes;
row2axes;
rowaxis;
endrow2axes;
layout overlay;
histogram height / scale=count yaxis=y2;
histogram height / scale=percent yaxis=y;
densityplot height / normal();
endlayout;
layout overlay;
histogram weight / scale=count yaxis=y2;
histogram weight / scale=percent yaxis=y;
densityplot weight / normal();
endlayout;
endlayout;
endgraph;
end;
proc sgrender data=sashelp.class template=y2axis;
run;
When using ROWAXES or
ROW2AXES blocks in a LATTICE layout, you nest within the block one
ROWAXIS statement for each row in the layout grid. The ROWAXIS statements
are applied sequentially to the rows, and each ROWAXIS statement specifies
the axis options for the Y or Y2 axes in its corresponding row. ROWAXIS
statements within the ROWAXES block apply to the Y axes, and ROWAXIS
statements within the ROW2AXES block apply to the Y2 axes. This example
has just a single row in the grid, so each block specifies only one
ROWAXIS statement. Notice that the ROWAXIS statement in the ROW2AXES
block does not use any options. Thus, it consolidates Y2 axes in the
row into a single, external Y2 axis, but it does not alter the default
features of that axis. For columns in the grid, the LATTICE layout
provides COLUMNAXES and COLUMN2AXES blocks. These blocks use COLUMNAXIS
statements to externalize X and X2 axes and specify their features.
When you use DATALATTICE
and DATAPANEL layouts, the layout dynamically generates a grid that
contains as many cells as can be produced from the combination of
classification values. In those layouts the axes are always external,
and you can use the COLUMNAXISOPTS=, COLUMN2AXISOPTS=, ROWAXISOPTS=,
and ROW2AXISOPTS= options to specify the features for the axes. The
settings on each option apply across the entire grid. For example,
if you specify the ROWAXISOPTS= option in a DATALATTICE layout, the
specified settings apply to the external Y axes in every row.