All template definitions
in the Graphics Template Language must start with a BEGINGRAPH statement
and conclude with an ENDGRAPH statement.
Within a BEGINGRAPH
block, one and only one GTL layout block is required. It can be a
LATTICE, GRIDDED, OVERLAY, OVERLAYEQUATED, OVERLAY3D, REGION, DATALATTICE,
or DATAPANEL layout block. This layout block can contain other nested
layout blocks and should contain at least one plot statement.
The GTL global statements
apply to the entire and can include such statements as title and footnote
statements, attribute maps, draw statements, conditional statements,
and so on. Any of these global statements can precede or follow the
GTL layout block.
By default, graphs are
rendered at 640px by 480px (4:3 aspect ratio). To change the output
size for a single graph, use the
DESIGNWIDTH= and
DESIGNHEIGHT= options in the BEGINGRAPH statement
for that graph. For example, the template in the
Example Program uses DESIGNHEIGHT= to change the graph height to 320px.
To prevent the graph width from automatically scaling to preserve
the 4:3 aspect ratio, it uses DESIGNWIDTH= to maintain the 640px width.
In this instance, the setting renders each graph cell as a 320px by
320px square. (The cells are square in this case, but the resulting
cell size depends on the graph definition and would not be the same
for all graphs.)
Note: To change the graph sizes
for all templates in the current SAS session, you can use the WIDTH=
and HEIGHT= options in the ODS GRAPHICS statement. Size settings in
the ODS GRAPHICS statement override size settings in the BEGINGRAPH
statement and remain in effect unless they are changed in another
ODS GRAPHICS statement. You can also use WIDTH= and HEIGHT= settings
in the graph style to modify the graphs sizes across template definitions.
Be aware, however, that if you explicitly manage the graph output
size, the graph elements might be scaled so that the size specification
is honored.
The following template
defines a square graph (equal height and width, 1:1 aspect ratio)
by setting the design width equal to the internal default height (480px).
The setting is made with DESIGNWIDTH=DEFAULTDESIGNHEIGHT:
Note: A “square graph”
means that the output graph’s width and height are equal. That
does not imply that the X and Y axis lengths are equal if the graph
contains only one cell.
proc template;
define statgraph squareplot;
dynamic title xvar yvar;
begingraph / designwidth=defaultDesignHeight;
entrytitle title;
layout overlayequated / equatetype=square;
scatterplot x=xvar y=yvar;
regressionplot x=xvar y=yvar;
endlayout;
endgraph;
end;
run;
If this template were
executed with the following GRENDER procedure statement, a 480px by
480px graph would be created:
proc sgrender data=mydata template="squareplot" ;
dynamic title="Square Plot" xvar="time1" yvar="time2";
run;
If the ODS GRAPHICS
statement’s WIDTH= or HEIGHT= options change the render width
or render height, the
squareplot template’s
1:1 aspect ratio would still be honored. Thus, both of the following
GRENDER procedure statements would create a 550px by 550px graph:
ods graphics / width=550px;
proc sgrender data=mydata template="squareplot" ;
dynamic title="Square Plot" xvar="time1" yvar="time2";
run;
ods graphics / height=550px;
proc sgrender data=mydata template="squareplot" ;
dynamic title="Square Plot" xvar="time1" yvar="time2";
run;