厚积薄发 发表于 2011-6-7 20:16

用SAS实现商业周刊经典风格 对绘图背景进行隔行填色

data ex;
input x y g color $;
cards;
1 2 1  Yahoo!
1 4 2 Google
2 5 1 Yahoo!
2 8 2 Google
4 12  1 Yahoo!
4 10 2 Google
5 9  1 Yahoo!
5 7 2 Google
;
data title_anno;
when=’b'; xsys=’3′; ysys=’3′; style=’solid’;
function=’move’; x=0; y=87;  output;
function=’bar’; x=100; y=100; color=’black’; output;
run;
data range_anno;
when=’b'; xsys=’1′; ysys=’1′; style=’solid’;
function=’move’; x=0; y=0; output;
function=’bar’;  x=100; y=20; color=”cxFFFBDD”;output;
function=’move’; x=0; y=20; output;
function=’bar’; color=”cxEEE3B4″; x=100; y=40; output;
function=’move’;x=0; y=40; output;
function=’bar’; color=”cxFFFBDD”; x=100; y=60; output;
function=’move’;x=0; y=60; output;
function=’bar’; color=”cxEEE3B4″; x=100; y=80; output;
function=’move’;x=0; y=80; output;
function=’bar’; color=”cxFFFBDD”; x=100; y=100; output;
run;
data range_anno1;
when=’b'; xsys=’1′; ysys=’1′;
function=’move’; x=0; y=20; output;
function=’bar’;  x=100; y=20; color=”cxD6CECD”;output;
function=’move’; x=0; y=40; output;
function=’bar’; color=”cxD6CECD”; x=100; y=40; output;
function=’move’;x=0; y=60; output;
function=’bar’; color=”cxD6CECD”; x=100; y=60; output;
function=’move’;x=0; y=80; output;
function=’bar’; color=”cxD6CECD”; x=100; y=80; output;
run;
data range_anno;
set range_anno range_anno1;
run;
FILENAME file “c:\bussiness.png”;
GOPTIONS reset=all noborder  Cback=”cxEEE3B4″ device=png  gsfname=file
vsize=7cm hsize=7cm
ymax=8cm xmax=9cm
htext=1.5   ;
axis1  major=none width=2 label=none  REFLABEL=none value=(h=1 color=black “Q1″ “Q2″ “Q3″ “Q4″ ) offset=(4,4);
axis2 color=black width=2 label=none order=(0 to 13 by 4) minor=none major=(h=1)  value=(h=1.0) offset=(0,2);
axis3 major=none label=none value=none;
pattern1 v=s color=’cxFF8E00′;
pattern2 v=s color=’cx004C7A’;
title j=l BCOLOR=black  COLOR=white h=3.5 font=CENTB  ” Bussniess weekly style”;
title2 j=l ” Internation compsdfdsfsfd”;
title3 j=l ” asdfd asdfdf dfsdfsd”;
legend1 label=none value=(HEIGHT=1.2 ‘Yahoo!’ ‘Google’ )  POSITION=(inside middle )  OFFSET=(-11,2.5)
shape=bar(.1in,.1in);
proc gchart data=ex anno=title_anno;
vbar g / discrete       type=sum
sumvar=y
maxis=axis1 raxis=axis2 GAXIS=axis3
coutline=gray33  caxis=”cxD6D3B8″
width=4
space=0
gspace=0
subgroup= color
group=x
legend=legend1
anno=range_anno ;
footnote justify=l h=1 font=swiss “  Data from **group”;
footnote2 justify=l h=1 font=swiss “  http://sxlion.blog.sohu.com”;
run;
quit;
下面是excelpro博客介绍的经典商业周刊风格的图表,对比一下相差无几。
这代码是相当的复杂,调试也比较费功夫。

本来准备在sgplot的band语句画区域作为背景来实现的,但是由于存在bar图与band不兼容的情况,于是只好转向anno了。见SAS公司详细说明。
There are four basic types of plots that you can create with the SGPLOT procedure:
Basic plots
scatter, series, step, band, needle, and vector plots
Fit and confidence plots
loess, regression, and penalized B-spline curves, and ellipses
Distribution plots
box plots, histograms, and normal and kernel density estimates
Categorization plots
dot plots, bar charts, and line plots
Not all of the plot types can be used together in the same PROC SGPLOT step. The following table shows which of the plot types can be used together


data ex;
input x y ;
cards;
1 2
2 7
4 12
5 11
6  9
7  8
;
title ;
footnote;
proc sgplot data=ex noautolegend;
SERIES  x=x y=y/LINEATTRS=(color=blue thickness=6) ;
band x=x lower=0 upper=2.5 / OUTLINE  transparency=.8 LINEATTRS=(color=black) fillattrs=(color=cxEEE3B4) NOOUTLINE;
band x=x lower=2.5 upper=5  / OUTLINE transparency=.7 LINEATTRS=(color=black) fillattrs=(color=orange) NOOUTLINE;
band x=x lower=5 upper=7.5 /OUTLINE transparency=.8 LINEATTRS=(color=black) fillattrs=(color=cxEEE3B4) NOOUTLINE;
band x=x lower=7.5 upper=10  / OUTLINE transparency=.7 LINEATTRS=(color=black) fillattrs=(color=orange) NOOUTLINE;
band x=x lower=10 upper=12.5 /OUTLINE transparency=.8 LINEATTRS=(color=black) fillattrs=(color=cxEEE3B4) NOOUTLINE;
yaxis values=(0 to 12 by 3)   min=0   max=13 valueshint;
xaxis values=(0 to 8 by 2)   min=0   max=8 valueshint;
run;
来源:数据挖掘学院

平平凡凡的我 发表于 2011-12-30 14:34

不错的东东

alair003 发表于 2012-2-6 11:04

schnee 发表于 2012-2-6 16:53

顶!!!!!!!

jt202010 发表于 2012-2-19 10:45

{:3_41:}{:3_41:}{:3_41:}{:3_41:}

老牦 发表于 2012-2-19 23:10

顶!!!!!!!

飞雪灬无痕 发表于 2012-3-4 19:51

学习了。。。。。。。。

hahaysw 发表于 2012-3-10 09:53

不错的东西,数学中国做的图相当好看啊!

540109558 发表于 2012-3-10 12:56

相当的不简单啊

秋の名山で戦 发表于 2014-1-16 22:20

哇 太强了 效果相当好
页: [1] 2
查看完整版本: 用SAS实现商业周刊经典风格 对绘图背景进行隔行填色