首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在SAS中使用proc gchart为垂直条形图分配颜色

在SAS中使用proc gchart为垂直条形图分配颜色
EN

Stack Overflow用户
提问于 2014-02-11 00:40:57
回答 1查看 2.1K关注 0票数 1

在PROC GCHART中,创建条形图时,垂直条形图的颜色由PATTERN语句决定。PATTERN语句根据值的字母顺序或层次顺序为条形分配颜色。我如何根据一个值具体地分配一个颜色?例如,如果我的价值观是“男孩”和“女孩”,我如何才能使“男孩”的价值出现在蓝色,而不管“女孩”是否存在,反之亦然?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-11 15:35:23

不幸的是,如果您使用的是SAS/ map,则不能使用属性映射,这是处理此问题的方法。如果您有SAS 9.2+,您可以使用option (PROC SGPLOT),它有此选项。attrmap将proc连接到一个数据集,该数据集存储变量的值以及与该变量的每个值相关联的颜色(或其他属性)。

一个来自SGPLOT上的SAS文档页面的例子

代码语言:javascript
复制
*create dummy dataset;
data finances;
format income dollar8. expense dollar8.;
length expensetype $ 9;
input Year incometype $ income expensetype $ expense;
datalines;
2000 Salary 20000 Utilities 4000
2000 Bonus   2000 Rent      7000
2000 Gifts    500 Food      8000 
2001 Salary 25000 Utilities 5000
2001 Bonus   1000 Rent      8000
2001 Gifts    200 Food      6000 
2002 Salary 23000 Utilities 4500
2002 Bonus    500 Rent      9000
2002 Gifts    500 Food      7000
;
run;

*Create attribute map.  ID = used to specify its use later, usually matches the variable but does not have to.  Value is the value you are changing the color/etc. for.  Then variables appropriate to what you are changing and to what, so fillcolor here for example.  ;
data attrmap;
length value $ 9 fillcolor $ 9; *I find that problems with attrmaps usually are due to length differences in dataset variables vs attrmap variables;
retain linecolor "black";  *using black for all of them;
input id $ value $ fillcolor $;
datalines;
income  Salary    blue
income  Bonus     gray
income  Gifts     lightgray
expense Utilities red
expense Rent      yellow
expense Food      orange
;
run;


proc sgplot data=finances dattrmap=attrmap; *specifying the attrmap here;
yaxis label="Dollars";
vbarparm category=year response=income / group=incometype attrid=income  /*using the attrmap here */
         barwidth=0.4 discreteoffset=-0.2 name="income"; 
vbarparm category=year response=expense / group=expensetype attrid=expense
         barwidth=0.4 discreteoffset=0.2 name="expense"; 
keylegend "income" / position=bottomleft title="Income";
keylegend "expense" / position=bottomright title="Expenses";
run;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21690858

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档