Certain
combinations of contained statements produce unexpected results. This
section examines why these combinations do not produce the expected
graph.
Consider
the following template code, which generates a warning in the log:
proc template;
define statgraph test;
begingraph;
layout overlay;
boxplot x=age y=weight;
regressionplot x=age y=weight;
endlayout;
endgraph;
end;
run;
proc sgrender data=sashelp.class template=test;
run;
WARNING: REGRESSIONPLOT statement cannot be placed under a layout OVERLAY with a
discrete axis. The plot will not be drawn.
When multiple
statements that potentially contribute to axis construction are placed
in the layout, the layout must verify that all data that is mapped
to a particular axis is of the same type (all numeric, or all character,
or all time). In addition, the layout must verify that each plot can
use the requested axis type(s). In this case, the first statement
in the layout is a BOXPLOT. Statements such as BOXPLOT, BOXPLOTPARM,
BARCHART, and BARCHARTPARM treat the X=column as a categorical variable
(regardless of data type) and build a DISCRETE (categorical) axis.
Therefore, because BOXPLOT is the first statement in this example
layout, it determines that the X axis is set to DISCRETE, and subsequent
plots must be compatible with a discrete axis.
Many computed
plots, such as REGRESSIONPLOT, LOESSPLOT, and ELLIPSE, require both
X and Y axes to be of LINEAR type, which is a standard numeric interval
axis type. Had you specified a SCATTERPLOT instead of a REGRESSIONPLOT,
there would be no problem because a SCATTERPLOT can be displayed on
either a DISCRETE or LINEAR X and Y axis. The end result of this example
is a graph containing only the box plot output.
In this
next example, the REGRESSIONPLOT and BOXPLOT statements have been
switched:
layout overlay;
regressionplot x=age y=weight;
boxplot x=age y=weight;
endlayout;
WARNING: BOXPLOT statement has a conflict with the axis type. The plot will not be drawn.
In this
case, the REGRESSIONPLOT (first plot) has fixed the type of the X
axis to be LINEAR. Now the BOXPLOT is blocked because it needs a DISCRETE
X axis. The end result of this example is a graph containing only
the regression line.
Because
a SCATTERPLOT can be included on either LINEAR or DISCRETE axes, you
might think the following combination is valid:
layout overlay;
scatterplot x=age y=weight;
boxplot x=age y=weight;
endlayout;
WARNING: BOXPLOT statement has a conflict with the axis type. The plot will not be drawn.
In this
case, the SCATTERPLOT (first statement) sets the X or Y axis type
to LINEAR if the variable for that axis is numeric—even though
the data might be categorical in nature. However, if the variable
is character, the SCATTERPLOT must use a DISCRETE axis. So, once again
the BOXPLOT is not displayed. If you switch the statements, both plots
are drawn because after the X axis is fixed to be DISCRETE, the SCATTERPLOT
can display numeric values on a DISCRETE axis.
When a
character variable is used, the axis-type conflict often does not
arise. The following combination works regardless of statement order.
In either case, the DISCRETE X axis will display a combination of
AGE values with box plots above and SEX values with scatter points
above.
layout overlay;
scatterplot x=sex y=weight;
boxplot x=age y=weight;
endlayout;