Sample 24920: Labeling data points in a two-dimensional plot
/***************************************************************/
/* Labeling data points in a plot can emphasize or clarify */
/* their values. The data points are labeled with the Annotate */
/* facility. */
/***************************************************************/
/* Set graphics options */
goptions reset=all ftext=centxi htext=3 gunit=pct colors=(black) border;
/* Create the input data set, GAMES. GAMES contains the cities in */
/* which the events were held from 1976 through 1992 and the */
/* cost of the broadcast rights. */
data games;
input place $ 1-11 cost;
datalines;
Montreal 25
Moscow 87
Los Angeles 225
Seoul 309
Barcelona 401
;
/* Create a format for the values of COST. The AMTFMT. format */
/* adds a comma and an M to the values and prefixes the values */
/* with a dollar sign ($). Because AMTFMT. is defined in a */
/* PICTURE statement, AMTFMT, affects only the display of values. */
proc format;
picture amtfmt low-high='00,009M'
(prefix='$');
run;
/* Create the Annotate data set, LABELS. LABELS adds the cost to */
/* each data point. Since values of the plot variables are used */
/* to position the labels, the coordinate system must be */
/* absolute data values (2). */
data labels;
length function style text $ 8;
retain function 'label' xsys ysys '2' hsys '3' style 'centxi'
size 4 when 'a' color 'black';
drop place cost;
set games end=lastob; /* The PLACE and COST variables from GAMES */
/* determine the values of the */
xc=place; y=cost; /* XC and Y variables. XC is used instead of */
/* X because PLACE is a character variable. */
text=left(put(cost,amtfmt.)); /* The formatted values of COST are */
/* displayed as the text. */
if _n_=1 then position='C'; /* The value of POSITION changes, depending */
/* upon the data point's */
else if lastob then position='A'; /* location on the plot line. */
else position='B'; output;
run;
/* Add the title and footnotes. */
title1 height=5 'Cost of U.S. Broadcast Rights for the Olympics';
footnote1 font=swissl height=2.5 justify=left ' SAS/GRAPH'
move=(+0,+.5) '02'x move=(+0,-.5) ' Software'
justify=right 'GAMES ';
/* Modify the appearance of the axes. */
/* The VALUE= options in the AXIS1 statement stacks the tick mark */
/* labels by adding JUSTIFY=CENTER between the text strings. */
axis1 label=none
order=('Montreal' 'Moscow' 'Los Angeles' 'Seoul' 'Barcelona')
value=(tick=1 'Montreal' justify=center '1976'
tick=2 'Moscow' justify=center '1980'
tick=3 'Los Angeles' justify=center '1984'
tick=4 'Seoul' justify=center '1988'
tick=5 'Barcelona' justify=center '1992');
axis2 label=('$U.S.,' justify=right 'Millions') order=(0 to 500 by 100);
/* Define the pattern for the area in the plot. */
pattern1 color=bioy value=solid;
symbol1 color=bioy value=none interpol=join; /* Select the color and */
/* interpolation method. */
/* Produce the plot. The PLOT statement includes the annotation defined */
/* in the LABELS data set. */
proc gplot data=games;
plot cost*place / areas=1 haxis=axis1 vaxis=axis2
href= 'Moscow' 'Los Angeles' 'Seoul' chref=black
vref=100 to 400 by 100 cvref=black vminor=0
cframe=blue annotate=labels;
run;
quit;

This sample uses Annotate to label data points in a Two-Dimensional Plot.
This example is detailed in SASGRAPH Software Examples
Version 6 First Edition.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> GPLOT Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Elements ==> Labels
|
| Date Modified: | 2005-08-31 03:03:16 |
| Date Created: | 2004-11-11 11:08:01 |
Operating System and Release Information
| SAS System | SAS/GRAPH | All | n/a | n/a |