SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 781|回复: 0
打印 上一主题 下一主题

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

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2010-10-22 13:32:35 | 只看该作者

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

From sxlion's blog on Sohu

<div style="FONT-SIZE: 14px; LINE-HEIGHT: 160%">
<p>&nbsp;&nbsp;&nbsp;&nbsp;商业周刊的经典风格。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<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&nbsp; Yahoo!<br />1 4&nbsp;2 Google<br />2 5&nbsp;1 Yahoo!<br />2 8&nbsp;2 Google<br />4 12&nbsp; 1&nbsp;Yahoo!<br />4 10 2 Google<br />5 9&nbsp; 1&nbsp;Yahoo!<br />5 7 2 Google<br />;<br />data title_anno;<br />when='b'; xsys='3'; ysys='3'; style='solid';<br />&nbsp;&nbsp; function='move'; x=0; y=87;&nbsp; output;<br />&nbsp;&nbsp; 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';&nbsp; x=100; y=20; color=&quot;cxFFFBDD&quot;;output;<br />function='move'; x=0; y=20; output;<br />function='bar'; color=&quot;cxEEE3B4&quot;; x=100; y=40; output;<br />function='move';x=0; y=40; output;<br />function='bar'; color=&quot;cxFFFBDD&quot;; x=100; y=60; output;<br />function='move';x=0; y=60; output;<br />function='bar'; color=&quot;cxEEE3B4&quot;; x=100; y=80; output;<br />function='move';x=0; y=80; output;<br />function='bar'; color=&quot;cxFFFBDD&quot;; 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';&nbsp; x=100; y=20; color=&quot;cxD6CECD&quot;;output;<br />function='move'; x=0; y=40; output;<br />function='bar'; color=&quot;cxD6CECD&quot;; x=100; y=40; output;<br />function='move';x=0; y=60; output;<br />function='bar'; color=&quot;cxD6CECD&quot;; x=100; y=60; output;<br />function='move';x=0; y=80; output;<br />function='bar'; color=&quot;cxD6CECD&quot;; x=100; y=80; output;</p>
<p>run;<br />data range_anno;<br />&nbsp; set range_anno range_anno1;<br />&nbsp; run;<br />FILENAME file &quot;c:\bussiness.png&quot;;<br />GOPTIONS reset=all noborder&nbsp; Cback=&quot;cxEEE3B4&quot; device=png&nbsp; gsfname=file<br />vsize=7cm hsize=7cm&nbsp; &nbsp;<br />&nbsp;ymax=8cm&nbsp;xmax=9cm&nbsp;&nbsp; <br />htext=1.5&nbsp;&nbsp; ;<br />axis1&nbsp; major=none width=2 label=none&nbsp; REFLABEL=none value=(h=1 color=black &quot;Q1&quot; &quot;Q2&quot; &quot;Q3&quot; &quot;Q4&quot; ) offset=(4,4); <br />axis2 color=black width=2 label=none order=(0 to 13 by 4) minor=none major=(h=1)&nbsp; value=(h=1.0) offset=(0,2);<br />axis3 major=none label=none value=none;<br />pattern1 v=s color='cxFF8E00';&nbsp; <br />pattern2 v=s color='cx004C7A';&nbsp; <br />title j=l BCOLOR=black&nbsp; COLOR=white h=3.5 font=CENTB&nbsp; &quot; Bussniess weekly style&quot;; <br />title2 j=l &quot; Internation compsdfdsfsfd&quot;;<br />title3 j=l &quot; asdfd asdfdf dfsdfsd&quot;;<br />legend1 label=none value=(HEIGHT=1.2 'Yahoo!' 'Google' )&nbsp; POSITION=(inside middle )&nbsp; OFFSET=(-11,2.5)<br />&nbsp;shape=bar(.1in,.1in);</p>
<p>proc gchart data=ex anno=title_anno;<br />&nbsp;&nbsp; vbar g / discrete&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type=sum <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sumvar=y &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; maxis=axis1 raxis=axis2 GAXIS=axis3<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; coutline=gray33&nbsp; caxis=&quot;cxD6D3B8&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width=4<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; space=0<br />&nbsp;&nbsp; gspace=0<br />&nbsp;&nbsp; subgroup= color<br />&nbsp;&nbsp; group=x<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; legend=legend1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; anno=range_anno ;<br />footnote justify=l h=1 font=swiss &quot;&nbsp; Data from **group&quot;; <br />footnote2 justify=l h=1 font=swiss &quot;&nbsp; <!-- m --><a class="postlink" href="http://sxlion.blog.sohu.com">http://sxlion.blog.sohu.com</a><!-- m -->&quot;; <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>&nbsp;</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&nbsp;<br />4 12<br />5 11<br />6&nbsp; 9<br />7&nbsp; 8<br />;<br />title ;<br />footnote;<br />proc sgplot data=ex noautolegend;<br />&nbsp; SERIES&nbsp; x=x y=y/LINEATTRS=(color=blue thickness=6) ;<br />&nbsp; band x=x lower=0 upper=2.5 / OUTLINE&nbsp; transparency=.8 LINEATTRS=(color=black) fillattrs=(color=cxEEE3B4) NOOUTLINE;<br />&nbsp; band x=x lower=2.5 upper=5 &nbsp;/ OUTLINE transparency=.7 LINEATTRS=(color=black) fillattrs=(color=orange) NOOUTLINE;<br />&nbsp; band x=x lower=5 upper=7.5 /OUTLINE transparency=.8 LINEATTRS=(color=black) fillattrs=(color=cxEEE3B4) NOOUTLINE;<br />&nbsp; band x=x lower=7.5 upper=10 &nbsp;/ OUTLINE transparency=.7 LINEATTRS=(color=black) fillattrs=(color=orange) NOOUTLINE;<br />&nbsp; band x=x lower=10 upper=12.5 /OUTLINE transparency=.8 LINEATTRS=(color=black) fillattrs=(color=cxEEE3B4) NOOUTLINE;<br />&nbsp; yaxis values=(0 to 12 by 3)&nbsp;&nbsp; min=0&nbsp;&nbsp; max=13 valueshint;<br />&nbsp; xaxis values=(0 to 8 by 2)&nbsp;&nbsp; min=0&nbsp;&nbsp; max=8 valueshint;<br />run;<br /></p></div>
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2026-2-3 22:01 , Processed in 0.067433 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表