SAS官网的一个例子,程序注释详细,annotate语句相关内容比较多,关键语句不多。
- /* AXIS and BUBBLE statement options create a bubble */
- /* plot divided by reference lines into quadrants. The */
- /* Annotate facility positions the labels for the */
- /* quadrant, reference lines and bubbles. */
- /*******************************************************/
- goptions reset=global gunit=pct cback=gray88 ctext=white
- ftext=swissl htext=2.5 border;
- /* Create input data set, AUTODATA. AUTODATA contains */
- /* the results of an informal local survey of selected */
- /* automobiles. SHARE is the percent of total autos */
- /* surveyed. RATING indicates practicality vs. */
- /* sportiness on a scale of 1 to 10. PRICE is cost in */
- /* thousands of dollars. */
- data autodata;
- input auto $ 17. share rating price;
- datalines;
- Mazda Miata .10 9.4 15.2
- Chevy S-10 .10 2.9 13.8
- Infiniti M30 .075 7.2 24.3
- Ford Taurus .10 4.3 13.3
- Plymouth Voyager .20 1.8 13.2
- Toyota Cressida .15 6.0 23.7
- Honda Civic .10 3.7 7.0
- Acura Integra .175 6.5 12.1
- ;
- /* Create the annotate data set, LABELS. LABELS adds */
- /* text to the quadrants and labels the bubbles with the */
- /* make of auto represented. Because the value of WHEN */
- /* is a (after), Annotate adds the text after the plot */
- /* is drawn. */
- data labels;
- length color $ 8 text $ 17;
- retain function 'label' hsys '3' style 'swissi' when 'a';
- if _n_=1 then
- do;
- xsys='1'; ysys='1'; size=3; color='blue';
- /* The labels are positioned using the absolute percent */
- /* of the data area, the coordinate system 1. */
- y=97; /* Vertical position for labels across the top of the plot. */
- x=1; position='C'; text='Economical and'; output;
- position='F'; text='Sporty'; output;
- x=50; position='B'; output; /* The value of TEXT remains 'Sporty'. */
- x=99; position='A'; text='Expensive and'; output;
- position='D'; text='Sporty'; output;
- y=50; /* Vertical position for the two vertical reference line labels. */
- x=1; position='F'; text='Economical'; output;
- x=99; position='D'; text='Expensive'; output;
- y=5; /* Vertical position for labels across the bottom of the plot. */
- x=1; position='C';text='Economical and'; output;
- position='F'; text='Practical'; output;
- x=50; position='E'; output; /* The value of TEXT remains 'Practical'. */
- x=99; position='A'; text='Expensive and'; output;
- position='D'; text='Practical'; output;
- end;
- /* Values from AUTODATA provide the text and position of the bubble labels. */
- /* Since the values of plot variables position the bubble labels, the */
- /* coordinate system is absolute data values (2). */
- set autodata;
- drop share rating price auto;
- text=auto; x=price; y=rating; xsys='2'; ysys='2'; position='5';
- style='swiss'; size=2.5; color='red'; output;
- run;
- /* Add the title and footnotes. */
- title1 height=5
- 'Market Analysis of Selected Automobiles';
- footnote1 justify=left ' SAS/GRAPH' move=(+0,+.5) '02'x move=(+0,-.5)
- ' Software' justify=right 'MARKET ';
- /* Create axis definitions */
- /* ORIGIN= aligns the plot with the title by specifying the same */
- /* distance from the left edge as the MOVE= in TITLE1. */
- axis1 order=(5 to 27) origin=(3,10) length=65 label=none value=none
- major=none minor=none;
- /* OFFSET= offsets the ends of the vertical axis to prevent a collision */
- /* between the bubble and the axis frame. Other options suppress lables */
- /* and tick marks. */
- axis2 order=(0 to 10) offset=(2,2) length=80 value=none label=none
- major=none minor=none ;
- /* Produce the bubble plot. Reference line options in the BUBBLE */
- /* statement draw and color the dashed lines that divide the quadrants. */
- /* BCOLOR= selects the color of the bubbles. CTEXT= affects the color */
- /* of the bubble value displayed by BLABEL. The BUBBLE statment includes */
- /* the annotation defined in the LABELS data set. NOTE statements */
- /* explicitly place text to the right of the plot. */
- proc gplot data=autodata;
- format share percent7.1;
- note height=2 move=(70,25) 'Bubble size and labels'
- move=(70,20) 'represent the market share,'
- move=(70,15) 'in percent, of autos'
- move=(70,10) 'in this survey.';
- bubble rating*price=share / bsize=12 bcolor=red blabel ctext=red
- href=16 chref=blue lhref=2 haxis=axis1
- vref=5 cvref=blue lvref=2 vaxis=axis2
- cframe=white annotate=labels;
- run;
- quit;
复制代码