Sample 24920: Label data points in a two-dimensional plot using PROC GPLOT and Annotate
This sample uses PROC GPLOT together with the Annotate facility to label data points in a two-dimensional plot.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample uses PROC GPLOT together with the Annotate facility to label data points in a two-dimensional plot.
The graphics output in the Results tab was produced using SASĀ® 9.2. Submitting the sample code with releases of SAS prior to SAS 9.2 might produce different results.
/* Set the graphics environment */
goptions reset=all border cback=white htitle=12pt;
/* 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
;
run;
/* 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 text $ 8 style $ 25;
retain function 'label' xsys ysys '2' hsys '3'
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 and Y variables. XC is used */
/* instead of X because PLACE is a character variable. */
xc=place; y=cost;
style="'Albany AMT/bold'";
/* The formatted values of COST are */
/* displayed as the text. */
text=left(put(cost,amtfmt.));
/* The value of POSITION changes, depending on */
/* the data point's location on the plot line. */
if _n_=1 then position='C';
else if lastob then position='A';
else position='B';
output;
run;
/* Add a title to the graph */
title1 'Cost of U.S. Broadcast Rights for the Olympics';
/* 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=vibg value=solid;
symbol1 color=vibg value=none interpol=join;
/* 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
annotate=labels cframe=beige;
run;
quit;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.

This sample uses PROC GPLOT together with the Annotate facility to label data points in a two-dimensional plot.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> GPLOT Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Elements ==> Annotation 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 |