This example
creates a two-celled graph that shows linear and loess regression
fits. The template uses a LATTICE layout with two columns.
Two-Celled Linear and Loess Regression Graph
Here is the
code for the output display.
proc template;
define statgraph mygraph;
dynamic XVAR YVAR;
begingraph / designwidth=480px designheight=320px;
layout lattice / columns=2;
layout overlayequated / equatetype=square;
entry "Linear Regression Fit" /
valign=top textattrs=(weight=bold);
scatterplot x=XVAR y=YVAR / markerattrs=(color=red) datatransparency=.7;
regressionplot x=XVAR y=YVAR;
endlayout;
layout overlayequated / equatetype=square;
entry "Loess Fit" /
valign=top textattrs=(weight=bold);
scatterplot x=XVAR y=YVAR / markerattrs=(color=red) datatransparency=.7;
loessplot x=XVAR y=YVAR;
endlayout;
endlayout;
endgraph;
end;
run;
proc sgrender data=sashelp.iris template=mygraph;
dynamic xvar="SepalLength" yvar="SepalWidth";
run;
Here is a brief description
of the code.
-
The DYNAMIC statement
creates dynamic variables named XVAR and YVAR. This feature enables
you to specify different names for the X and Y data values when you
render the graph.
dynamic XVAR YVAR;
-
The DESIGNWIDTH= and
DESIGNHEIGHT= options in the BEGINGRAPH statement control the graph
size.
begingraph / designwidth=480px designheight=320px;
-
The LAYOUT statement
begins the outer LAYOUT block and specifies a lattice with two columns.
layout lattice / columns=2;
-
The outer LAYOUT block
contains two nested LAYOUT blocks, one for each overlay cell in the
lattice. Each cell contains a scatter plot and a fit plot. The main
distinction between the two cells is the type of fit plot. The first
cell contains a regression plot and the second cell contains a loess
plot.
An ENTRY
statement specifies the text for each cell title. The title for the
first cell is "Linear Regression Fit." In the second LAYOUT block,
the title is "Loess Fit."
The MARKERATTRS=
option in the SCATTERPLOT statement specifies a red color for the
scatter plot markers. In addition, 70% transparency is assigned to
the scatter plot to increase the visibility of the fit plot.
layout overlayequated / equatetype=square;
entry "Linear Regression Fit" /
valign=top textattrs=(weight=bold);
scatterplot x=XVAR y=YVAR / markerattrs=(color=red) datatransparency=.7;
regressionplot x=XVAR y=YVAR;
endlayout;
layout overlayequated / equatetype=square;
entry "Loess Fit" /
valign=top textattrs=(weight=bold);
scatterplot x=XVAR y=YVAR / markerattrs=(color=red) datatransparency=.7;
loessplot x=XVAR y=YVAR;
endlayout;
-
The SGRENDER procedure
specifies the library and data set to use for the graph. The DYNAMIC
statement specifies which columns to use for the X and Y variables
of the graph, respectively.
proc sgrender data=sashelp.iris template=mygraph;
dynamic xvar="SepalLength" yvar="SepalWidth";
run;