Rendering a Graph with Annotations
In order to render a graph with annotations, you must include at least one ANNOTATE
statement in the graph template. The ANNOTATE statement causes the annotations to
be read from the SG annotation data set and drawn on the graph. You can place an
ANNOTATE statement anywhere in the template. However, the drawing spaces that are
specified for the annotations must be valid in the context of the ANNOTATE statement
location. The order in which the annotations are drawn with respect to the graph
elements depends on the LAYER option for the annotations. By default, annotations are
always drawn on the front layer. In that case, the annotations are drawn after the graph
elements are drawn and appear on top of the plots and other graph elements. If you
specify BACK for the annotation layer, the annotations are drawn before the graph
elements are drawn and appear behind the plots and other graph elements.
When you render your graph, you must include the SGANNO= option in the
SGRENDER statement to specify the name of your SG annotation data set.For
examples, see “Example 1: Creating Custom Labels” on page 405 and “Example 2:
Displaying Subsets of Annotations in Axis-Aligned Insets” on page 409.
By default, the ANNOTATE statement draws all of the annotations that are stored in the
SG annotation data set. You can use the ANNOTATE statement ID= option to display a
subset of these annotations. Subsetting your annotations enables you to use one SG
annotation data set with multiple plots. To use the ID= option, the observations for the
annotations must contain an ID column. The ID column is a character column that stores
a unique character value that identifies the subset to which each annotation belongs.
When the ID="identifier" option is used in the ANNOTATE statement, only the
annotations with ID column values that match the identifier value are displayed. The
remaining annotations are ignored. For more information about the ANNOTATE
statement ID= option, see “ANNOTATE Statement” in SAS Graph Template Language:
Reference. For an example, see “Example 2: Displaying Subsets of Annotations in Axis-
Aligned Insets” on page 409.
Example 1: Creating Custom Labels
This example demonstrates how to use the Graphic Template Language (GTL)
annotation facility to create custom category labels for a horizontal bar chart. The bar
chart plots the average highway mileage (response) by vehicle type (category).
Ordinarily, the category labels for a horizontal bar chart appear on the Y axis to the left
Example 1: Creating Custom Labels 405