数学建模社区-数学中国

标题: 用SAS实现商业周刊经典风格 对绘图背景进行隔行填色 [打印本页]

作者: 厚积薄发    时间: 2011-6-7 20:16
标题: 用SAS实现商业周刊经典风格 对绘图背景进行隔行填色
d1.png data ex;
5 `, r: R% P; n9 t! [input x y g color $;
" a. G- G6 |# d4 Ecards;3 k& u% Z4 S9 O3 o# V( L1 d  P& \
1 2 1  Yahoo!
" G3 |" v+ `& O$ v1 4 2 Google
" g9 F/ U  |1 K) T4 s" z2 5 1 Yahoo!5 ^. _% C% P# S! Y3 A2 U3 j" u4 k1 c
2 8 2 Google( }7 c# V' y3 Z0 a9 T
4 12  1 Yahoo!6 B' z0 h0 w4 S* [+ s' W% D$ J4 K
4 10 2 Google; c4 e5 C! ~2 s+ l( o
5 9  1 Yahoo!1 e, w; P$ z- W: i( e4 C
5 7 2 Google
8 U! c9 l  R! [0 v;5 ^$ E/ j3 ^2 w/ E" h4 s" H9 u, n5 L
data title_anno;2 j8 ]& D% o4 k- Y2 w. ^
when=’b'; xsys=’3′; ysys=’3′; style=’solid’;
9 y' a# J( Z, [4 L0 qfunction=’move’; x=0; y=87;  output;
  {3 W% _! y8 _function=’bar’; x=100; y=100; color=’black’; output;- B1 L7 B# ?9 R4 R- @" k
run;
! {7 b  ~, ]& |. P2 d+ Z5 d" {8 Fdata range_anno;
2 t) L9 F! F' v2 ~4 Lwhen=’b'; xsys=’1′; ysys=’1′; style=’solid’;2 ^; P5 V/ R4 W. n: f. D
function=’move’; x=0; y=0; output;- ?  w7 M& v' O; g7 `$ A- K. v
function=’bar’;  x=100; y=20; color=”cxFFFBDD”;output;/ d9 G( c. w: S! W
function=’move’; x=0; y=20; output;
4 R1 p; U( a- W% y+ A- `" gfunction=’bar’; color=”cxEEE3B4″; x=100; y=40; output;
* F" n* F4 h/ n: d2 K" Ufunction=’move’;x=0; y=40; output;
9 y+ f/ _: s. j' C4 @7 u% @function=’bar’; color=”cxFFFBDD”; x=100; y=60; output;
$ @( z- ]$ [; D3 b& D+ Xfunction=’move’;x=0; y=60; output;
4 X( M" ]: z  L1 |: ]: \function=’bar’; color=”cxEEE3B4″; x=100; y=80; output;) j8 d# ~! n  u) i
function=’move’;x=0; y=80; output;! Q" @4 Z& W, M8 A9 _2 a
function=’bar’; color=”cxFFFBDD”; x=100; y=100; output;
! M- A" }6 R9 z, Y  Lrun;
9 F1 D6 f1 Z/ j; [' K, Sdata range_anno1;
3 i/ D4 u1 w6 W) N& Zwhen=’b'; xsys=’1′; ysys=’1′;
0 F4 e7 P* C8 _% e3 p9 e, sfunction=’move’; x=0; y=20; output;
0 K1 A* e. r+ Cfunction=’bar’;  x=100; y=20; color=”cxD6CECD”;output;
2 B; b9 P3 g. B9 k, C( m6 V3 [function=’move’; x=0; y=40; output;4 }+ F) S$ [, j, h. I5 \
function=’bar’; color=”cxD6CECD”; x=100; y=40; output;5 M, I" m8 p' `9 A2 i2 L
function=’move’;x=0; y=60; output;$ D! M9 G* v/ l, w
function=’bar’; color=”cxD6CECD”; x=100; y=60; output;
& G0 O7 X, e! l1 N. O0 s- q( A/ hfunction=’move’;x=0; y=80; output;
/ U0 t+ z, S/ m, o* {) ]function=’bar’; color=”cxD6CECD”; x=100; y=80; output;/ e% R6 [( I1 @( l
run;
9 `6 i0 O8 e7 y0 f2 O5 H. W$ }data range_anno;
. {$ h# _0 S5 y2 \" G, u% F3 A- V0 Y& @set range_anno range_anno1;1 Y0 `0 k0 |+ z( m, l" `' e
run;. D0 A* b, `9 p9 H
FILENAME file “c:\bussiness.png”;
3 k) O) I- Q8 C. VGOPTIONS reset=all noborder  Cback=”cxEEE3B4″ device=png  gsfname=file* F$ d8 Z+ V+ S3 V/ B
vsize=7cm hsize=7cm
/ A  Q- I5 ]) u8 U0 I* ~ymax=8cm xmax=9cm
: a5 ^0 v; A# C, j2 c& I; phtext=1.5   ;
3 D" ?5 ~/ Y( T) B7 _axis1  major=none width=2 label=none  REFLABEL=none value=(h=1 color=black “Q1″ “Q2″ “Q3″ “Q4″ ) offset=(4,4);4 j) J! o& ~/ [8 W+ }  e6 I0 T2 ]9 n! j
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);. ~3 x/ \! f! x( w) u$ l7 [% m  a
axis3 major=none label=none value=none;/ I4 ]0 X) @1 y9 r* @6 O2 `( l
pattern1 v=s color=’cxFF8E00′;0 S8 U2 C$ k* c4 B4 H
pattern2 v=s color=’cx004C7A’;
4 B, Z. @" ~8 W' dtitle j=l BCOLOR=black  COLOR=white h=3.5 font=CENTB  ” Bussniess weekly style”;
5 }! L! ~; C* W" e7 Wtitle2 j=l ” Internation compsdfdsfsfd”;
  ]4 N2 u( B8 S* Vtitle3 j=l ” asdfd asdfdf dfsdfsd”;
' g$ j" a, Z: H$ jlegend1 label=none value=(HEIGHT=1.2 ‘Yahoo!’ ‘Google’ )  POSITION=(inside middle )  OFFSET=(-11,2.5)
3 u0 l+ I$ w! x% e& q8 r9 F" yshape=bar(.1in,.1in);$ T5 T3 O' s4 Y7 |; y; j
proc gchart data=ex anno=title_anno;
2 ?5 k: m* m1 M( r# Dvbar g / discrete       type=sum3 N' M/ W5 [& i2 A
sumvar=y% h, h  a- @3 C% Y3 w
maxis=axis1 raxis=axis2 GAXIS=axis3
2 E6 `: w  u/ x' h% ]' l- b% Mcoutline=gray33  caxis=”cxD6D3B8″: y& N7 E6 ^: ?% Y" [  _9 G
width=4$ b( b4 P! f) P
space=0
9 E: h% X8 p5 {! {! `gspace=0
8 A3 R  v; _6 T3 J- z0 S) @subgroup= color& F( h' U. b2 u3 I1 w9 ^* D$ A% E
group=x
/ f" g! P% Z% o: E9 g# @$ `  llegend=legend1$ B# t. U4 u1 m; k2 f8 w; y% ^
anno=range_anno ;5 x! [' _/ s2 O4 o# e0 q5 x
footnote justify=l h=1 font=swiss “  Data from **group”;# j) _6 c' |* p0 G; @# Z. G
footnote2 justify=l h=1 font=swiss “  http://sxlion.blog.sohu.com”;' |' H1 W7 n# k3 F2 c  Q2 e$ c$ ]  e
run;
9 T' K( M. U% U7 {( L. _& oquit;
# t: f! S/ O+ m4 K下面是excelpro博客介绍的经典商业周刊风格的图表,对比一下相差无几。, [! n( n$ s# a3 J) Y4 S
这代码是相当的复杂,调试也比较费功夫。) [7 y5 E; [! G, p
d2.gif 9 C3 Y& D/ r/ C2 h
本来准备在sgplot的band语句画区域作为背景来实现的,但是由于存在bar图与band不兼容的情况,于是只好转向anno了。见SAS公司详细说明。0 Y+ ]$ Z! h1 ~6 D# h  X- W
There are four basic types of plots that you can create with the SGPLOT procedure:8 ?  K6 f. r$ U+ T
Basic plots$ S* s' ]1 R1 w9 W
scatter, series, step, band, needle, and vector plots
: w! f& S9 l" _( g% tFit and confidence plots; K4 k+ c0 M6 H$ r4 T) D" I
loess, regression, and penalized B-spline curves, and ellipses; m7 W0 Z9 G& K- s% q
Distribution plots; y8 x. ]) l' p' l( a- q
box plots, histograms, and normal and kernel density estimates
# D. R1 e- _( D. T& F) [6 bCategorization plots
& q* L& {& n( A  x3 E% qdot plots, bar charts, and line plots$ t+ h* p- [) }
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
, R. {3 L( \5 |5 L
" @$ S# g  Z- D9 a
; W3 k5 I/ K4 h# p7 b- ?2 Gdata ex;
2 I! h$ {; N+ ?0 b% U( Binput x y ;
0 n1 Y* O5 k1 G1 acards;
* Q$ U0 p5 e. H$ s" i+ S5 [" K, v1 2
3 N" t8 f! q* W# ?0 H2 7( F% v1 w8 S- H! d
4 12
" {' e+ J& ?# q2 e' B& j5 114 G0 k( u1 i9 M2 P
6  9
6 S8 g: O( v" K6 G! G7  8
! P/ D* \7 d; p5 Z;% Q2 l  a% i, ~$ ^0 u
title ;
1 X. ]( m) t' i; t. u5 R/ w% Hfootnote;- S; ], U3 u: h& h5 S2 `( u
proc sgplot data=ex noautolegend;
% @+ S; t8 ^* V- O. }4 eSERIES  x=x y=y/LINEATTRS=(color=blue thickness=6) ;: \' d, l& r9 u2 x
band x=x lower=0 upper=2.5 / OUTLINE  transparency=.8 LINEATTRS=(color=black) fillattrs=(color=cxEEE3B4) NOOUTLINE;
/ S% t' E6 v: Y! p  B9 h$ bband x=x lower=2.5 upper=5  / OUTLINE transparency=.7 LINEATTRS=(color=black) fillattrs=(color=orange) NOOUTLINE;
: B; m' S: a! g3 Z+ @+ Uband x=x lower=5 upper=7.5 /OUTLINE transparency=.8 LINEATTRS=(color=black) fillattrs=(color=cxEEE3B4) NOOUTLINE;
* ?, S. G/ c" U' Fband x=x lower=7.5 upper=10  / OUTLINE transparency=.7 LINEATTRS=(color=black) fillattrs=(color=orange) NOOUTLINE;8 V6 [  e" E- F8 L
band x=x lower=10 upper=12.5 /OUTLINE transparency=.8 LINEATTRS=(color=black) fillattrs=(color=cxEEE3B4) NOOUTLINE;
/ h( r3 S  E" H' @& q$ s# U0 Ryaxis values=(0 to 12 by 3)   min=0   max=13 valueshint;
3 r) K5 [+ o0 G4 H. gxaxis values=(0 to 8 by 2)   min=0   max=8 valueshint;4 V. }1 e# q9 ^- U, x
run;2 Y# L: U' i+ u) N
来源:数据挖掘学院
作者: 平平凡凡的我    时间: 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