SAS中文论坛
标题:
用SAS实现商业周刊经典风格 对绘图背景进行隔行填色
[打印本页]
作者:
shiyiming
时间:
2010-10-22 13:32
标题:
用SAS实现商业周刊经典风格 对绘图背景进行隔行填色
From sxlion's blog on Sohu
<div style="FONT-SIZE: 14px; LINE-HEIGHT: 160%">
<p> 商业周刊的经典风格。</p>
<p> <img style="DISPLAY: block; MARGIN: 0px auto 10px; TEXT-ALIGN: center" alt="" src="http://1862.img.pp.sohu.com.cn/images/blog/2010/8/12/22/27/12b1a145282g214.jpg" border="0" /><a href="http://pp.sohu.com/photoview-329786140-36248359.html" target="_blank"></a></p>
<p>data ex;<br />input x y g color $;<br />cards;<br />1 2 1 Yahoo!<br />1 4 2 Google<br />2 5 1 Yahoo!<br />2 8 2 Google<br />4 12 1 Yahoo!<br />4 10 2 Google<br />5 9 1 Yahoo!<br />5 7 2 Google<br />;<br />data title_anno;<br />when='b'; xsys='3'; ysys='3'; style='solid';<br /> function='move'; x=0; y=87; output;<br /> function='bar'; x=100; y=100; color='black'; output;<br />run;<br />data range_anno;<br />when='b'; xsys='1'; ysys='1'; style='solid';<br />function='move'; x=0; y=0; output;<br />function='bar'; x=100; y=20; color="cxFFFBDD";output;<br />function='move'; x=0; y=20; output;<br />function='bar'; color="cxEEE3B4"; x=100; y=40; output;<br />function='move';x=0; y=40; output;<br />function='bar'; color="cxFFFBDD"; x=100; y=60; output;<br />function='move';x=0; y=60; output;<br />function='bar'; color="cxEEE3B4"; x=100; y=80; output;<br />function='move';x=0; y=80; output;<br />function='bar'; color="cxFFFBDD"; x=100; y=100; output;<br />run;<br />data range_anno1;<br />when='b'; xsys='1'; ysys='1'; <br />function='move'; x=0; y=20; output;<br />function='bar'; x=100; y=20; color="cxD6CECD";output;<br />function='move'; x=0; y=40; output;<br />function='bar'; color="cxD6CECD"; x=100; y=40; output;<br />function='move';x=0; y=60; output;<br />function='bar'; color="cxD6CECD"; x=100; y=60; output;<br />function='move';x=0; y=80; output;<br />function='bar'; color="cxD6CECD"; x=100; y=80; output;</p>
<p>run;<br />data range_anno;<br /> set range_anno range_anno1;<br /> run;<br />FILENAME file "c:\bussiness.png";<br />GOPTIONS reset=all noborder Cback="cxEEE3B4" device=png gsfname=file<br />vsize=7cm hsize=7cm <br /> ymax=8cm xmax=9cm <br />htext=1.5 ;<br />axis1 major=none width=2 label=none REFLABEL=none value=(h=1 color=black "Q1" "Q2" "Q3" "Q4" ) offset=(4,4); <br />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);<br />axis3 major=none label=none value=none;<br />pattern1 v=s color='cxFF8E00'; <br />pattern2 v=s color='cx004C7A'; <br />title j=l BCOLOR=black COLOR=white h=3.5 font=CENTB " Bussniess weekly style"; <br />title2 j=l " Internation compsdfdsfsfd";<br />title3 j=l " asdfd asdfdf dfsdfsd";<br />legend1 label=none value=(HEIGHT=1.2 'Yahoo!' 'Google' ) POSITION=(inside middle ) OFFSET=(-11,2.5)<br /> shape=bar(.1in,.1in);</p>
<p>proc gchart data=ex anno=title_anno;<br /> vbar g / discrete type=sum <br /> sumvar=y <br /> maxis=axis1 raxis=axis2 GAXIS=axis3<br /> coutline=gray33 caxis="cxD6D3B8"<br /> width=4<br /> space=0<br /> gspace=0<br /> subgroup= color<br /> group=x<br /> legend=legend1<br /> anno=range_anno ;<br />footnote justify=l h=1 font=swiss " Data from **group"; <br />footnote2 justify=l h=1 font=swiss " <!-- m --><a class="postlink" href="http://sxlion.blog.sohu.com">http://sxlion.blog.sohu.com</a><!-- m -->"; <br />run;<br />quit;</p>
<p>下面是excelpro博客介绍的经典商业周刊风格的图表,对比一下相差无几。</p>
<p>这代码是相当的复杂,调试也比较费功夫。</p>
<p><img style="DISPLAY: block; MARGIN: 0px auto 10px; TEXT-ALIGN: center" alt="" src="http://1822.img.pp.sohu.com.cn/images/blog/2010/8/12/18/19/12b19162a6cg213.gif" border="0" /></p>
<p><br />本来准备在sgplot的band语句画区域作为背景来实现的,但是由于存在bar图与band不兼容的情况,于是只好转向anno了。见SAS公司<a href="http://blog.sohu.com/manage/entry.do?m=edit&id=157942407&t=shortcut#" target="_blank">详细说明</a>。</p>
<p>
<table cellspacing="0" cellpadding="0">
<tbody>
<tr valign="top">
<td><a name="a003199431">Plot Content</a></td></tr></tbody></table></p>
<p></p>
<p>There are four basic types of plots that you can create with the SGPLOT procedure:</p>
<dl>
<dt>Basic plots </dt>
<dd>
<p>scatter, series, step, band, needle, and vector plots</p></dd>
<dt>Fit and confidence plots </dt>
<dd>
<p>loess, regression, and penalized B-spline curves, and ellipses</p></dd>
<dt>Distribution plots </dt>
<dd>
<p>box plots, histograms, and normal and kernel density estimates</p></dd>
<dt>Categorization plots </dt>
<dd>
<p>dot plots, bar charts, and line plots</p></dd></dl>
<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</p><img style="DISPLAY: block; MARGIN: 0px auto 10px; TEXT-ALIGN: center" alt="" src="http://1801.img.pp.sohu.com.cn/images/blog/2010/8/12/23/10/12b1a2024fcg214.jpg" border="0" />
<p> </p>
<p><img style="DISPLAY: block; MARGIN: 0px auto 10px; TEXT-ALIGN: center" alt="" src="http://1811.img.pp.sohu.com.cn/images/blog/2010/8/12/23/9/12b1a1f9910g213.jpg" border="0" /></p>
<p>data ex;<br />input x y ;<br />cards;<br />1 2 <br />2 7 <br />4 12<br />5 11<br />6 9<br />7 8<br />;<br />title ;<br />footnote;<br />proc sgplot data=ex noautolegend;<br /> SERIES x=x y=y/LINEATTRS=(color=blue thickness=6) ;<br /> band x=x lower=0 upper=2.5 / OUTLINE transparency=.8 LINEATTRS=(color=black) fillattrs=(color=cxEEE3B4) NOOUTLINE;<br /> band x=x lower=2.5 upper=5 / OUTLINE transparency=.7 LINEATTRS=(color=black) fillattrs=(color=orange) NOOUTLINE;<br /> band x=x lower=5 upper=7.5 /OUTLINE transparency=.8 LINEATTRS=(color=black) fillattrs=(color=cxEEE3B4) NOOUTLINE;<br /> band x=x lower=7.5 upper=10 / OUTLINE transparency=.7 LINEATTRS=(color=black) fillattrs=(color=orange) NOOUTLINE;<br /> band x=x lower=10 upper=12.5 /OUTLINE transparency=.8 LINEATTRS=(color=black) fillattrs=(color=cxEEE3B4) NOOUTLINE;<br /> yaxis values=(0 to 12 by 3) min=0 max=13 valueshint;<br /> xaxis values=(0 to 8 by 2) min=0 max=8 valueshint;<br />run;<br /></p></div>
欢迎光临 SAS中文论坛 (https://mysas.net/forum/)
Powered by Discuz! X3.2