我想要生成一个“步骤”图(CDF),并试图使用dattrmap选项更改行颜色。但颜色并没有改变。下面是我的代码:
%MACRO ATRRMAP(fich=,var=);
proc freq data=&fich noprint;
tables &var/nocum nopercent norow nocol out=freq&var;
format _all_;
where &var^=.;
run;
data test;
set freq&var end=eof;
call symputx("mvCAT"||strip(_N_),&var);
if eof then call symputx("NB",_N_);
run;
data myattrmap;
length id $20 value 3 linecolor $10 pattern 3 fillcolor $20;
%do i=1 %to &NB;
id='myid';
value = &&mvCAT&i;
linecolor=cats("grey",put(&i*5,hex2.));
%if &i=1 or &i=5 or &i=9 %then %do;
pattern = 1;
%end;%else %if &i=2 or &i=6 or &i=10 %then %do;
pattern = 15;
%end;%else %if &i=3 or &i=7 or &i=11 %then %do;
pattern = 2;
%end;%else %if &i=4 or &i=8 or &i=12 %then %do;
pattern = 8;
%end;%else %do;
pattern = 41;
%end;
fillcolor=cats("grey",put(&i*5,hex2.));
output;
%end;
run;
%MEND ATRRMAP;生成的数据如下所示:
id value pattern fillcolor
myid -6 1 CXbdc3c7
myid -5 2 CXbdc3c7
myid -4 8 CXbdc3c7然后,我使用了sgplot:
PROC SGPLOT DATA=cumul sganno=annotation NOBORDER dattrmap=myattrmap;
STEP X=variable Y=percent/GROUP=newgroup attrid=myid;
YAXIS LABEL="Cumulative percentage of patients" VALUES=(0 TO 100 BY
10);
XAXIS LABEL=" " VALUES=(-4 to 4 by 0.5) ;
KEYLEGEND /TITLE=" " LOCATION=INSIDE POSITION=BOTTOMRIGHT ACROSS=1
DOWN=3 NOBORDER;
RUN;与sgplot一起使用的数据myfile如下所示:
variable percent newgroup
-3.66 2.70 -6
-3.41 5.40 -6
-3.26 8.11 -6
-3.28 5.8 -5
-2.97 13.51 -5我想要一个灰色梯度。但首先,我想简单地选择,与数据地图,颜色线在我的情节。我试着用填充色和线条色,但它不起作用。我试图在SGPLOT语句中直接更改这个颜色,并使用styleattrs的datacontrastcolor选项,它可以工作。有人看到我错过了什么吗?
发布于 2018-11-19 23:50:11
它必须是组=变量,即控制颜色、形状和图案的变量。您是按NEWGROUP对变量进行分组,而不是按值进行分组。但是,您可以创建一个代理来完成这个任务,如果这是您想要的话。如果没有更多关于你需要什么的细节,我不知道我们如何能帮你找到一份工作,但这确实解释了为什么它现在不起作用。
来自文件:
值变量的值是有效的数据组值。这些值区分大小写。使用GROUP=选项在plot语句中分配数据组。
假设需要基于NEWGROUP的不同颜色的行,下面是如何修改代码的方法。注意到,我已经大大简化了您的代码,并且在如何指定颜色方面存在问题--我暂时忽略了这些问题,让您来解决。这些值目前是在宏中硬编码的。我还建议将if _n_部分更改为使用MOD()函数,因为您的数据中似乎有某种模式。它可能不起作用,但值得考虑。
*create fake data;
data myfile;
input variable percent newgroup $;
cards;
-3.66 2.70 group1
-3.41 5.40 group1
-3.26 8.11 group1
-3.28 5.8 group2
-2.97 13.51 group2
;;;;
run;
*macro to create attribute map;
%MACRO ATRRMAP(fich=,var=);
proc freq data=&fich noprint;
tables &var/nocum nopercent norow nocol out=freq&var (drop=percent);
format _all_;
where not missing(&var);
run;
data myattrmap;
length id $20 value $20 linecolor $10 pattern 3 fillcolor $20;
set freq&var.;
id='myid';
value = &var.;
if _n_ =1 then
linecolor = 'CXbdbdbd';
else if _n_=2 then
linecolor = 'CX636363';
*linecolor=cats("grey",put(_n_*5,hex2.));
if _n_ in (1, 5, 9) then
pattern = 1;
else if _n_ in (2, 6, 10) then
pattern = 15;
else if _n_ in (3, 7, 11) then
pattern = 2;
else if _n_ in ( 4, 8, 12) then
pattern=8;
else pattern = 14;
fillcolor=cats("grey",put(_n_*5,hex2.));
output;
run;
%MEND ATRRMAP;
*create attribute map for newgroup;
%ATRRMAP(fich=myfile, var=newgroup);
*plot graph;
PROC SGPLOT DATA=myfile NOBORDER dattrmap=myattrmap;
STEP X=variable Y=percent/GROUP=newgroup attrid=myid;
YAXIS LABEL="Cumulative percentage of patients" VALUES=(0 TO 100 BY
10);
XAXIS LABEL=" " VALUES=(-4 to 4 by 0.5);
KEYLEGEND /TITLE=" " LOCATION=INSIDE POSITION=BOTTOMRIGHT ACROSS=1
DOWN=3 NOBORDER;
RUN;配色方案名称的方法和规则被发现这里。
https://stackoverflow.com/questions/53378774
复制相似问题