加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

[转载]Proc Gplot:运用Gplot作图

(2011-12-15 10:35:37)
标签:

转载

分类: 统计学
[SAS]Proc Gplot的一些使用

Proc Gplot:运用Gplot作图

 

原文地址:http://www2.sas.com/proceedings/sugi31/239-31.pdf

转载请注明出处:http://blog.sina.com.cn/s/blog_5d3b177c0100b68a.html 

 

Data如下,为一个时间序列数据。这个数据是自己编的,只是为了方便测试程序。

data t112;

input nh_tot fg_tot year;

cards;

90 90 1970

120 100 1971

170 110 1972

240 120 1973

330 130 1974

440 140 1975

560 150 1976

690 160 1977

850 170 1978

1090 180 1979

1290 190 1980

1590 200 1981

;

run;

 

1 基本用法:

proc gplot data=t112;

   plot nh_tot*year;

run;

结果:

http://s2/bmiddle/5d3b177cg5bd8f16178e1Gplot:运用Gplot作图" TITLE="[转载]Proc Gplot:运用Gplot作图" />

2 Gplot的一些基本设置

goptions ftext='Arial' htext=2 gunit=pct; 

symbol1 value=dot interpol=join;  

title "NATIONAL HEALTH CARE EXPENDITURES: 1970-1982";

footnote "Source: Health-United States-2003";  

proc gplot data=t112;

   plot nh_tot*year;

run;

结果:

http://s16/bmiddle/5d3b177cg5bd8f2e0411fGplot:运用Gplot作图" TITLE="[转载]Proc Gplot:运用Gplot作图" />

 

3 改变标题title和脚注footnote

goptions ftext='Arial' htext=2 gunit=pct;

symbol1 v=dot i=join;

title height=4 "NATIONAL HEALTH CARE EXPENDITURES: 1970-1982";

footnote justify=right "Source: Health-United States-2003"; 

proc gplot data=t112;

   plot nh_tot*year;

run;

 

4 改变横坐标的label设置和纵坐标的显示尺度设置

options validvarname=upcase;

goptions ftext='Arial' htext=2 gunit=pct;

symbol1 v=dot i=join;

axis1 label=(angle=90 "AMOUNT (IN BILLIONS)") minor=(n=3);

axis2 order=(1970 to 1982 by 2) minor=(n=4);

title h=4 "NATIONAL HEALTH CARE EXPENDITURES: 1970-1982";

footnote j=right "Source: Health-United States-2003";

proc gplot data=t112;

   plot nh_tot*year/vaxis=axis1 haxis=axis2;

   format nh_tot comma.;

run;

http://s12/bmiddle/5d3b177cg5bd8f411593bGplot:运用Gplot作图" TITLE="[转载]Proc Gplot:运用Gplot作图" />

 

5 对各文字和横纵坐标加颜色

options validvarname=upcase;

goptions ftext='Arial' htext=2 gunit=pct ctext=green;

symbol1 v=dot i=join c=blue h=2.5;

axis1 label=(angle=90 "AMOUNT (IN BILLIONS)") minor=(n=3) color=blue;

axis2 order=(1970 to 1982 by 2) minor=(n=4) color=blue;

title1 h=4 "NATIONAL HEALTH CARE EXPENDITURES: 1970-1982";

footnote1 j=right "Source: Health-United States-2003";

proc gplot data=t112;

   plot nh_tot*year/vaxis=axis1 haxis=axis2;

   format nh_tot comma.;

run;

http://s14/bmiddle/5d3b177cg5bd8f579293dGplot:运用Gplot作图" TITLE="[转载]Proc Gplot:运用Gplot作图" />

 

6 将所有的文字设置为绿色,而图形和坐标轴设置为蓝色

options validvarname=upcase;

goptions ftext='Arial' htext=2 gunit=pct ctext=green;

symbol1 v=dot i=join c=blue h=2.5;

axis1 label=(angle=90 rotate=0 "AMOUNT (IN BILLIONS)") minor=(n=3) ;

axis2 order=(1970 to 1982 by 2) minor=(n=4) offset=(2,2);

title h=4 font='Arial/bo' "NATIONAL HEALTH CARE EXPENDITURES: 1970-1982";

footnote j=right "Source: Health-United States-2003";

proc gplot data=t112;

   plot nh_tot*year/vaxis=axis1 haxis=axis2 caxis=blue;

   format nh_tot comma.;

run;

http://s9/bmiddle/5d3b177cg5bd8f68e6358Gplot:运用Gplot作图" TITLE="[转载]Proc Gplot:运用Gplot作图" />

 

7 增加别外一个图像,图像叠加:

options validvarname=upcase;

goptions ftext='Arial' htext=2 gunit=pct ctext=green;

symbol1 v=dot i=join c=blue h=2.5 l=1;

symbol2 v=dot i=join h=2.5 l=3;

axis1 label=(angle=90 rotate=0 "AMOUNT (IN BILLIONS)") minor=(n=3);

axis2 order=(1970 to 1982 by 2) minor=(n=4) offset=(2,2);

title h=4 f='Arial/bo' "NATIONAL HEALTH CARE EXPENDITURES: 1970-1982";

footnote j=right "Source: Health-United States-2003";

proc gplot data=t112;

   plot (nh_tot fg_tot)*year/overlay vaxis=axis1 haxis=axis2 caxis=blue;

   format nh_tot comma.;

run;

 

 

8 设置曲线的样式:

options validvarname=upcase;

goptions ftext='Arial' htext=2 gunit=pct ctext=green csymbol=blue;

symbol1 v=dot i=join c=blue h=2.5 l=1;

symbol2 v=dot i=join h=2.5 l=3;

axis1 label=(angle=90 rotate=0 "AMOUNT (IN BILLIONS)") minor=(n=3);

axis2 order=(1970 to 1982 by 2) minor=(n=4) offset=(2,2);

title h=4 f='Arial/bo' "NATIONAL HEALTH CARE EXPENDITURES: 1970-1982";

footnote j=right "Source: Health-United States-2003";

proc gplot data=t112;

   plot (nh_tot fg_tot)*year/overlay vaxis=axis1 haxis=axis2 caxis=blue;

   format nh_tot comma.;

run;

http://s6/bmiddle/5d3b177cg5bd8f7cf9265Gplot:运用Gplot作图" TITLE="[转载]Proc Gplot:运用Gplot作图" />

 

9 增加一个legend,也可以对legend进行调整:

options validvarname=upcase;

goptions ftext='Arial' htext=2 gunit=pct ctext=green csymbol=blue;

symbol1 v=dot i=join h=2.5 l=1;

symbol2 v=dot i=join h=2.5 l=3;

axis1 label=(angle=90 rotate=0 "AMOUNT (IN BILLIONS)") minor=(n=3);

axis2 order=(1970 to 1982 by 2) minor=(n=4) offset=(2,2);

title h=4 f='Arial/bo' "NATIONAL HEALTH CARE EXPENDITURES: 1970-1982";

footnote j=right "Source: Health-United States-2003";

proc gplot data=t112;

   plot (nh_tot fg_tot)*year/overlay vaxis=axis1 haxis=axis2 caxis=blue legend;

   format nh_tot comma.;

run;

http://s14/bmiddle/5d3b177cg5bd8fd42dd8dGplot:运用Gplot作图" TITLE="[转载]Proc Gplot:运用Gplot作图" />

 

10 对默认的legend进行修改:

options validvarname=upcase;

goptions ftext='Arial' htext=2 gunit=pct ctext=green csymbol=blue;

symbol1 v=dot i=join h=2.5 l=1;

symbol2 v=dot i=join h=2.5 l=3;

axis1 label=(angle=90 rotate=0 "AMOUNT (IN BILLIONS)") minor=(n=3);

axis2 order=(1970 to 1982 by 2) minor=(n=4) offset=(2,2);

legend1 label=none value=(j=left "TOTAL" j=left "FEDERAL GOVT")

        mode=protect position=(top inside left)

        cborder=blue cshadow=blue

        across=1 shape=line(10);

title h=4 f='Arial/bo' "NATIONAL HEALTH CARE EXPENDITURES: 1970-1982";

footnote j=right "Source: Health-United States-2003";

proc gplot data=t112;

   plot (nh_tot fg_tot)*year/overlay vaxis=axis1 haxis=axis2 caxis=blue legend=legend1;

   format nh_tot comma.;

run;

http://s11/bmiddle/5d3b177cg5bd8fe2c2a3aGplot:运用Gplot作图" TITLE="[转载]Proc Gplot:运用Gplot作图" />

 

11 对曲线进行标注:

data my_labels;

   retain xsys ysys '2' function 'label'

          position '1' style "'Arial/bo'"

          color 'blue' cborder 'blue';

   set t112 end=last;

   if last then do;

      text=' FEDERAL GOVERNMENT '; x=year; y=fg_tot; output;

      text=' TOTAL '             ; x=year; y=nh_tot; output;

   end;

run;

goptions ftext='Arial' htext=2 gunit=pct ctext=green csymbol=blue;

options validvarname=upcase;

symbol1 f=marker v='C' i=join h=1.25;

symbol2 f=marker v='U' i=join h=1.25;

axis1 label=(angle=90 rotate=0 "AMOUNT (IN BILLIONS)") minor=(n=3);

axis2 order=(1970 to 1982 by 2) minor=(n=4) offset=(2,2);

title h=4 f='Arial/bo' "NATIONAL HEALTH CARE EXPENDITURES: 1970-1982";

footnote j=right "Source: Health-United States-2003";

proc gplot data=t112;

   plot (nh_tot fg_tot)*year/overlay vaxis=axis1 haxis=axis2 caxis=blue annotate=my_labels;

   format nh_tot comma.;

run;

http://s12/bmiddle/5d3b177cg5bd8ff5d666bGplot:运用Gplot作图" TITLE="[转载]Proc Gplot:运用Gplot作图" />

 

12 生成一个GIF图像文件

options validvarname=upcase;

goptions device=gif gsfname=gout xpixels=1024 ypixels=768

         ftext='Arial' htext=2 gunit=pct ctext=green csymbol=blue;

symbol1 f=marker v='C' i=join h=1.25;

symbol2 f=marker v='U' i=join h=1.25;

axis1 label=(angle=90 rotate=0 "AMOUNT (IN BILLIONS)") minor=(n=3);

axis2 order=(1970 to 1982 by 2) minor=(n=4) offset=(2,2);

legend1 label=none value=(j=left "TOTAL" j=left "FEDERAL GOVT")

        mode=protect position=(top inside left)

        cborder=blue cshadow=blue

        across=1 shape=symbol(6,1.25);

title h=4 f='Arial/bo' "NATIONAL HEALTH CARE EXPENDITURES: 1970-2000";

footnote j=right "Source: Health-United States-2003";

filename gout 'c:healthexp.gif';

proc gplot data=t112;

   plot (nh_tot fg_tot)*year/overlay vaxis=axis1 haxis=axis2 caxis=blue legend=legend1;

   format exp comma.;

run;

 

13 noframe选项,使得图像能自动调整适合的大小

options validvarname=upcase;

goptions ftext='Arial' htext=2 gunit=pct ctext=green csymbol=blue;

symbol1 v=dot i=join h=2.5 l=1;

symbol2 v=dot i=join h=2.5 l=3;

axis1 label=(angle=90 rotate=0 "AMOUNT (IN BILLIONS)") minor=(n=3);

axis2 order=(1970 to 1982 by 5) minor=(n=4) offset=(2,2);

legend1 label=none value=(j=left "TOTAL" j=left "FEDERAL GOVT")

        mode=protect position=(top inside left)

        cborder=blue cshadow=blue

        across=1 shape=line(10);

title h=4 f='Arial/bo' "NATIONAL HEALTH CARE EXPENDITURES: 1970-1982";

footnote j=right "Source: Health-United States-2003";

proc gplot data=t112;

   plot (nh_tot fg_tot)*year/overlay vaxis=axis1 haxis=axis2 caxis=blue legend=legend1 noframe;

   format nh_tot comma.;

run;

 

 http://s12/bmiddle/5d3b177cg5bd900b83ddbGplot:运用Gplot作图" TITLE="[转载]Proc Gplot:运用Gplot作图" />

 

 

0

  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有