Monday, March 21, 2011

Label overlay lines seperately by annotation

/* Set the graphics environment */
goptions reset=all cback=white border htitle=12pt;
     
 /* Create input data set, PRODCOST */
data prodcost (drop=tcprev tfc tvc tc);
   retain tcprev 0;
   input quan tfc tvc;
   tc=tfc+tvc;
   afc=tfc/quan;       /* average fixed cost    */
   avc=tvc/quan;       /* average variable cost */
   atc=tc/quan;        /* average total cost    */
   mc=tc-tcprev;       /* marginal cost         */
   tcprev=tc;
   datalines;
1    10   05
2    10   08
3    10   10
4    10   11
5    10   13
6    10   16
7    10   20
8    10   25
9    10   31
10   10   38
11   10   46
;
run;

data anno;
      set prodcost end=last;
      function='label';
      retain xsys ysys '2' hsys '9' position '6';
      size=3;
      if last then do;
            x=quan;
            y=afc; color='depk'; text='AFC'; output;
            y=avc; color='vibg'; text='AVC'; output;
            y=atc; color='mob';  text='ATC'; output;
            y=mc;  color='black'; text='MC'; output;
      end;
run;

 /* Create axis definitions */
axis1 minor=none offset=(1,8)
      label=('Thousands of Units');
axis2 order=(0 to 16 by 4) minor=(number=3 color=red height=.3 width=5) offset=(0,0)
      label=('Dollar Cost' justify=left '(in hundreds)');


symbol1 interpol=spline color=depk width=1;
symbol2 interpol=spline color=vibg width=1;
symbol3 interpol=spline color=mob  width=1;
symbol4 interpol=spline color=black width=1;
title1 'Projected cost of production';
proc gplot data=prodcost;
      plot (afc avc atc mc)*quan / overlay frame vaxis=axis2 haxis=axis1 annotate=anno;
run;
quit;

/* spline用来连接data成为一条曲线 */
/* overlay用来把图片叠加 */
/* minor用来设置小的刻度(major用来设置大的刻度) */
/* offset用来在坐标轴上起始/末尾位置留下空白 */
 




No comments:

Post a Comment