Previous Page | Next Page

Using Annotate Data Sets

Examples

The following examples show how to annotate graphics that are created with SAS/GRAPH procedures and how to build custom graphics:

Other examples that use Annotate data sets are as follows:


Labeling Cities on a Map

Features:

Annotate function:

LABEL

SYMBOL

Annotate variables:

HSYS

POSITION

SIZE

TEXT

WHEN

X and Y

XSYS

YSYS

Sample library member:

GANCITY

Map with Labeled Cities

[Map with Labeled Cities]

This example labels a map of the continental United States with the location and names of three cities. The GMAP procedure draws a map of the U.S. and an Annotate data set adds the stars and labels.

The DATA step that creates the Annotate data set gets the x and y coordinates of the cities to be labeled from the MAPS.USCITY data set. Because MAPS.USCITY stores projected coordinates in the X and Y variables, the DATA step does not need to reassign the variable values. Also because X and Y contain data values (the map data set coordinates), the XSYS and YSYS variables specify coordinate system 2, absolute data values. However, the HSYS variable that controls text height uses coordinate system 3, percent of the graphics output area.

See Projecting an Annotate Data Set for an example of labeling a map using map coordinates in units of latitude and longitude.

See The GMAP Procedure for more information on using map data sets.

 Note about code
goptions reset=all border;
 Note about code
data lower48;
   set maps.us;
   if state ne stfips("AK");
   if state ne stfips("HI");
   if state ne stfips("PR");
run;
 Note about code
data citystar;
   length function style color $ 8 position $ 1
          text $ 20;
   retain xsys ysys "2" hsys "3"
          when "a";
 Note about code
   set maps.uscity(keep=x y city state);
   if (city="Atlanta" and state=13)
       or city="Chicago"
       or city="Seattle";
 Note about code
   function="symbol"; style="marker"; text="V"; color="red"; size=5;
      output;
 Note about code
   function="label"; style=""; text=city; color="green";
      size=5; position="8"; output;
run;
 Note about code
title "Distribution Center Locations";
 Note about code
pattern value=mempty color=blue repeat=49;
 Note about code
proc gmap data=lower48 map=lower48;
   id state;
   choro state / annotate=citystar discrete nolegend;
run;
quit;

Labeling Subgroups in a Vertical Bar Chart

Features:

Annotate function:

LABEL (default)

Annotate variables:

MIDPOINT

POSITION

SUBGROUP

Sample library member:

GANVBAR

Bar Chart with Labeled Subgroups

[Bar Chart with Labeled Subgroups]

This example shows how to label subgroups in a vertical bar chart that is generated by the GCHART procedure. Each bar represents total orders for a city and is subgrouped by the type of order. The Annotate facility labels each subgroup with the number of orders for that category. The coordinates that position the subgroup labels are derived from the values of the GCHART procedure variables CITY (the chart (or midpoint) variable) and TYPE (the subgroup variable). These variables are assigned to the corresponding Annotate variable.

See The GCHART Procedure for more information on creating bar charts.

 Note about code
goptions reset=all border;
 Note about code
data sold;
   length type $ 10;
   input city $ units type $ ;
   datalines;
Atlanta  99 Printers
Atlanta 105 Plotters
Atlanta  85 Terminals
Paris   182 Printers
Paris   150 Plotters
Paris   157 Terminals
Sydney  111 Printers
Sydney  136 Plotters
Sydney  100 Terminals
;
run;
 Note about code
data barlabel;
   length color style $ 8;
   retain color "white" when "a" style "arial"
      xsys ysys "2" position "E" size 4 hsys "3";
   set sold;
   midpoint=city;
   subgroup=type;
   text=left(put(units,5.));
run;
 Note about code
title "Orders Received";
footnote j=r "GANVBAR";
 Note about code
axis1 label=none major=none minor=none style=0
      value=none;
axis2 label=none;
 Note about code
proc gchart data=sold;
   vbar city / type=sum
               sumvar=units
               subgroup=type
               width=17
               raxis=axis1
               maxis=axis2
               annotate=barlabel;
run;
quit;

Drawing a Circle of Stars

Features:

Annotate function:

BAR

CNTL2TXT

FRAME

LABEL

MOVE

PIECNTR

PIEXY

SYMBOL

Annotate variables:

COLOR

HSYS, XSYS, YSYS

LINE

STYLE

TEXT

X and Y

XLAST and YLAST

XLSTT and YLSTT

Sample library member:

GANCIRCL

Stars Positioned in a Circle with GANNO

[Stars Positioned in a Circle with GANNO]

This example shows how to use an Annotate data set to draw a flag that is composed of a rectangle and four stars. The stars are positioned by placing them on an imaginary circle. The program uses the PIECNTR and PIEXY functions to find the points on the circle and the CNTL2TXT programming function to transfer coordinate values. It also processes Annotate assignment statements in a DO loop. The GANNO procedure displays the Annotate graphics.

 Note about code
goptions reset=all border;
 Note about code
data flag;
   length function style color $ 8 text $ 30;
   retain xsys ysys hsys "3";
 Note about code
   function="frame"; output;
 Note about code
   function="label"; x=50; y=90; text="Flag of Micronesia";
      style=""; size=6; output;
 Note about code
   function="move"; x=20; y=30; output;
   function="bar"; x=80; y=80; color="blue";
      line=3; style="solid"; output;
 Note about code
do star_ang=0 to 270 by 90;
 Note about code
   function="piecntr"; x=50; y=55; size=15; output;
   function="piexy"; size=1; angle=star_ang; output;
 Note about code
   function="cntl2txt"; output;
   function="symbol"; style="marker"; text="V";
      angle=0; color="white"; size=10; x=.; y=.;
      output;
   end;
run;
 Note about code
proc ganno annotate=flag;
run;
quit;

Previous Page | Next Page | Top of Page