数学建模社区-数学中国
标题:
用SAS实现商业周刊经典风格 对绘图背景进行隔行填色
[打印本页]
作者:
厚积薄发
时间:
2011-6-7 20:16
标题:
用SAS实现商业周刊经典风格 对绘图背景进行隔行填色
2011-6-7 20:15 上传
下载附件
(7.88 KB)
data ex;
$ d9 Y) A" a+ Q
input x y g color $;
5 S3 e' ]8 W% d6 b, F8 S
cards;
! H* H+ s/ y, F" i# k
1 2 1 Yahoo!
5 f5 N1 ]- X4 g) Z9 G2 B
1 4 2 Google
* o5 b' J% i' V
2 5 1 Yahoo!
" y2 F) U w2 I7 k! B" [
2 8 2 Google
5 s7 E0 {0 y' B+ `/ e
4 12 1 Yahoo!
+ n/ J+ m' P4 ~' n' |
4 10 2 Google
) ]4 b! ^, |& f" ]
5 9 1 Yahoo!
8 ]$ o+ y2 W7 O( j" m4 h+ |
5 7 2 Google
3 K! `& a& q( f! A0 @
;
& N2 L! Z2 b) @4 W1 S
data title_anno;
9 D9 g$ E. k' p+ _+ a9 T
when=’b'; xsys=’3′; ysys=’3′; style=’solid’;
/ H( o( h8 W, R' ]' G
function=’move’; x=0; y=87; output;
7 n# Y9 t4 |. H- T) }
function=’bar’; x=100; y=100; color=’black’; output;
( z) c8 j# E2 M3 M: i4 @9 b! d
run;
c4 Y4 \' W/ X. d" b6 i8 p, t
data range_anno;
% |1 L8 J$ f* I& X4 J6 H' k# X5 |
when=’b'; xsys=’1′; ysys=’1′; style=’solid’;
! Z. a, ^! ?% J. j
function=’move’; x=0; y=0; output;
9 Z& L- C" o6 i x
function=’bar’; x=100; y=20; color=”cxFFFBDD”;output;
}8 p: X$ Z* B. W6 G8 c
function=’move’; x=0; y=20; output;
. n( W6 c. d- P9 ^ Q1 j7 Q( o
function=’bar’; color=”cxEEE3B4″; x=100; y=40; output;
( e! _0 \# s6 e
function=’move’;x=0; y=40; output;
7 b4 M6 V0 _- j& `
function=’bar’; color=”cxFFFBDD”; x=100; y=60; output;
7 h5 z8 I6 r0 Z2 ]' L1 J* f! e
function=’move’;x=0; y=60; output;
' C; h8 g- L8 {9 N- c) t! E
function=’bar’; color=”cxEEE3B4″; x=100; y=80; output;
+ b7 u+ ^) x* y
function=’move’;x=0; y=80; output;
6 ]1 }5 Z4 w- g
function=’bar’; color=”cxFFFBDD”; x=100; y=100; output;
1 ?& y' ~1 l3 v; u1 [2 g
run;
0 F5 I8 E6 h$ M3 R, X8 u# g. M$ ~& n+ V
data range_anno1;
) S1 O4 o' t1 l
when=’b'; xsys=’1′; ysys=’1′;
( ?% {7 S! o- t# f
function=’move’; x=0; y=20; output;
$ R7 J7 c' `2 K3 t0 Z; L( ]( w+ \
function=’bar’; x=100; y=20; color=”cxD6CECD”;output;
1 h% Y2 |& Z% S0 X% S; ~" T9 g
function=’move’; x=0; y=40; output;
; D" X c4 {; L) X
function=’bar’; color=”cxD6CECD”; x=100; y=40; output;
+ T# G( H% c/ O7 O
function=’move’;x=0; y=60; output;
6 Q5 |# q. R6 |3 q; `
function=’bar’; color=”cxD6CECD”; x=100; y=60; output;
6 I& J; \5 X5 A; q9 l
function=’move’;x=0; y=80; output;
- O$ ~: v; D+ E+ @4 m+ @
function=’bar’; color=”cxD6CECD”; x=100; y=80; output;
9 M( C% p" \! B1 y8 l+ [' D
run;
7 |. f# _& ~) E& {
data range_anno;
7 n1 J0 r3 U8 H/ a$ M% u L. N
set range_anno range_anno1;
% X3 M$ |8 y p$ p6 o0 _- C! Y
run;
% l1 a' s, H9 M( e
FILENAME file “c:\bussiness.png”;
+ Z7 Y/ g! x# k; B
GOPTIONS reset=all noborder Cback=”cxEEE3B4″ device=png gsfname=file
" C/ a. h1 k8 F$ V2 o
vsize=7cm hsize=7cm
% x. F" i! c% x$ [# |! T% M, |
ymax=8cm xmax=9cm
7 V* u/ A% `3 m. l
htext=1.5 ;
: C5 c4 A- Q4 ~8 O+ m
axis1 major=none width=2 label=none REFLABEL=none value=(h=1 color=black “Q1″ “Q2″ “Q3″ “Q4″ ) offset=(4,4);
2 g6 d9 l5 W8 Q$ U$ @& b0 k. y: H
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);
( s3 Z: ^5 I; E7 s1 z4 k/ B0 g: }
axis3 major=none label=none value=none;
9 B/ I( T% Y6 y4 N3 B+ m$ V
pattern1 v=s color=’cxFF8E00′;
' [+ D2 f% H2 N( T5 {
pattern2 v=s color=’cx004C7A’;
; C: K$ d( N; c! @' ]# u! V
title j=l BCOLOR=black COLOR=white h=3.5 font=CENTB ” Bussniess weekly style”;
0 K% u+ }9 Q5 \( ?& X. y# w5 b
title2 j=l ” Internation compsdfdsfsfd”;
. z% m+ e8 Y% C: y1 i2 N; P5 U
title3 j=l ” asdfd asdfdf dfsdfsd”;
x7 G J) A. v3 y$ _
legend1 label=none value=(HEIGHT=1.2 ‘Yahoo!’ ‘Google’ ) POSITION=(inside middle ) OFFSET=(-11,2.5)
- F1 a! J" g! ~8 T
shape=bar(.1in,.1in);
) }& `, b. q+ Z
proc gchart data=ex anno=title_anno;
4 f- n, C, J7 x! t$ W0 i4 P
vbar g / discrete type=sum
" q1 }; \3 r; ], o: _# I; `/ U Z
sumvar=y
+ G( o A2 S$ l" ?
maxis=axis1 raxis=axis2 GAXIS=axis3
* y# q) S! s1 t" s6 D0 U7 ~# W
coutline=gray33 caxis=”cxD6D3B8″
! Z$ ?2 @1 O5 y6 O
width=4
$ j; u! Z8 D/ n: V
space=0
) Q) M# N6 h9 }9 b4 K6 K( ^
gspace=0
- t: V- E1 a' n# C2 N+ \
subgroup= color
! O' _, L4 A* N/ Z5 h: Y+ |
group=x
' L" L. t) u2 a8 D7 f6 L
legend=legend1
6 p3 `& b/ O# P% k( Y' Y
anno=range_anno ;
. i" a! L ~' I0 U0 B1 Z1 f
footnote justify=l h=1 font=swiss “ Data from **group”;
7 N0 {) p( h& e
footnote2 justify=l h=1 font=swiss “
http://sxlion.blog.sohu.com
”;
- }1 U% l& ~5 a0 O' X9 {; S
run;
- a1 F2 c r! A+ c5 @
quit;
# \5 R8 Y; m* v. B5 ^9 S! P! Q
下面是excelpro博客介绍的经典商业周刊风格的图表,对比一下相差无几。
0 Q6 ~- t9 k+ _% p& U% @
这代码是相当的复杂,调试也比较费功夫。
* F' i# J) f7 F( }. |3 F
2011-6-7 20:15 上传
下载附件
(10.18 KB)
! \4 ?# Y% S7 ^/ |+ l
本来准备在sgplot的band语句画区域作为背景来实现的,但是由于存在bar图与band不兼容的情况,于是只好转向anno了。见SAS公司详细说明。
! {: }5 r |/ o; Z# X: i8 a
There are four basic types of plots that you can create with the SGPLOT procedure:
; P! f: \3 O0 _* h: g4 `9 r
Basic plots
2 B9 B% O$ G; r% H* m# ]) H/ o
scatter, series, step, band, needle, and vector plots
# t, c7 O# ~" _' k* s, B
Fit and confidence plots
% C: `9 Z7 m9 \3 W
loess, regression, and penalized B-spline curves, and ellipses
- ^- |; X) R; L. R2 n- K& a
Distribution plots
, m+ x u- e8 N: d5 Q3 L
box plots, histograms, and normal and kernel density estimates
; c. D t* `$ @8 N
Categorization plots
. y1 G3 m3 h+ Y9 Q& y: }7 g% X
dot plots, bar charts, and line plots
- y+ k; {+ E) R* R
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
$ F6 `4 C! f0 G/ {8 P5 n
$ }9 [& C2 O, [6 d* @0 o
" \/ a2 p2 e" L( k1 `/ f7 F2 L
data ex;
# `4 f+ t5 f5 b ~9 w9 g3 [" `* A
input x y ;
7 _0 z0 _) U0 i+ d
cards;
( q1 o- i3 ^# y, c8 M4 {9 p
1 2
( a0 r, I2 f8 ]" x h5 ]% V
2 7
: {" U9 s1 L0 D
4 12
- H( K% M6 A7 U
5 11
' Y+ P- X e0 W) V4 r4 G
6 9
" |( l$ {+ U/ y5 m- N A) f$ ]1 X
7 8
8 G! y. U0 Q2 g" |' ^
;
' y; c K( V0 k$ G* r6 U6 F
title ;
2 z* i o% O5 Q. k4 ^5 ~* c
footnote;
; k0 M2 a4 i, e s- y9 `0 a
proc sgplot data=ex noautolegend;
, K. I' T, M( k; H/ o
SERIES x=x y=y/LINEATTRS=(color=blue thickness=6) ;
! T3 ?# h3 f4 k' R& W! d1 V
band x=x lower=0 upper=2.5 / OUTLINE transparency=.8 LINEATTRS=(color=black) fillattrs=(color=cxEEE3B4) NOOUTLINE;
4 y* u, H2 V0 V. f. R1 y8 p! D* J" u
band x=x lower=2.5 upper=5 / OUTLINE transparency=.7 LINEATTRS=(color=black) fillattrs=(color=orange) NOOUTLINE;
" Z9 W% ~3 Q& }! K4 W4 t% r: q3 y' J
band x=x lower=5 upper=7.5 /OUTLINE transparency=.8 LINEATTRS=(color=black) fillattrs=(color=cxEEE3B4) NOOUTLINE;
) ~* a. }: G! x U5 J6 _
band x=x lower=7.5 upper=10 / OUTLINE transparency=.7 LINEATTRS=(color=black) fillattrs=(color=orange) NOOUTLINE;
. W+ W' z# r) T" d- }$ r
band x=x lower=10 upper=12.5 /OUTLINE transparency=.8 LINEATTRS=(color=black) fillattrs=(color=cxEEE3B4) NOOUTLINE;
6 T& d$ \$ G& l6 L3 \, d8 x# }
yaxis values=(0 to 12 by 3) min=0 max=13 valueshint;
6 v, |) h3 u% W
xaxis values=(0 to 8 by 2) min=0 max=8 valueshint;
/ D' Y9 }5 J7 y% M
run;
! m. ^* }! B9 U5 t* } |9 l, m
来源:数据挖掘学院
作者:
平平凡凡的我
时间:
2011-12-30 14:34
不错的东东
作者:
alair003
时间:
2012-2-6 11:04
看看,肯定能学到不少东西~!~!~@!~!~!~!~
8348932838256931
作者:
schnee
时间:
2012-2-6 16:53
顶!!!!!!!
作者:
jt202010
时间:
2012-2-19 10:45
作者:
老牦
时间:
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
哇 太强了 效果相当好
作者:
秋の名山で戦
时间:
2014-1-16 22:24
真心觉得是好贴 点128个赞
作者:
空木葬花
时间:
2014-8-16 17:07
非常感谢楼主!
欢迎光临 数学建模社区-数学中国 (http://www.madio.net/)
Powered by Discuz! X2.5