SGPLOT中Asterisk标记未按代码定义显示蓝色的技术咨询
SGPLOT星号标记颜色不匹配问题解决
问题现象
在以下SGPLOT代码中,指定为蓝色的Asterisk(星号)标记未显示设定的蓝色,反而呈现浅绿色:
ods graphics / attrpriority=none; proc sgplot data=unk; title 'Scatter Plot'; styleattrs datacolors=(blue lightyellow lightsalmon) datasymbols=(Asterisk Circlefilled Diamondfilled); scatter x=S y=M / group=A filledoutlinedmarkers markeroutlineattrs=(color=black thickness=1); run;
改用属性映射数据集测试后,问题依旧——星号标记还是不显示定义的蓝色:
data mattrs; retain linecolor "black"; infile datalines truncover; input ID Value markersymbol fillcolor; datalines; U N circlefilled lightyellow U R diamondfilled lightsalmon U S asterisk blue ; run; data unk; infile datalines truncover; input S $ Value $ M ID $; datalines; ZB N 3 U ZB R 5 U ZB S 10 U YQ N 11 U YQ R 6 U YQ S 7 U XI N 1 U XI R 5 U XI S 2 U TO N 9 U TO R 3 U TO S 10 U ; run; proc sgplot data=unk dattrmap=mattrs; scatter x=S y=M / group=Value attrid=U; yaxis min=0 max=100 type=log logstyle=logexpand logbase=10 grid; run;
原因及解决方法
核心原因是:Asterisk属于非填充型标记,SGPLOT对填充型和非填充型标记的颜色控制逻辑不同:
- 填充型标记(如Circlefilled、Diamondfilled)用
fillcolor控制内部颜色,filledoutlinedmarkers选项也仅对这类标记生效; - 非填充型标记(如Asterisk)没有填充色,颜色由
markercolor控制,而非fillcolor。
针对第一个代码的修改方案
方案1:改用填充型星号标记(Starfilled),这样filledoutlinedmarkers和datacolors的设置会正常生效:
ods graphics / attrpriority=none; proc sgplot data=unk; title 'Scatter Plot'; styleattrs datacolors=(blue lightyellow lightsalmon) datasymbols=(Starfilled Circlefilled Diamondfilled); /* 替换为填充型星号 */ scatter x=S y=M / group=A filledoutlinedmarkers markeroutlineattrs=(color=black thickness=1); run;
方案2:如果坚持使用Asterisk,需要直接指定标记的边缘颜色(因为非填充标记只有边缘):
ods graphics / attrpriority=none; proc sgplot data=unk; title 'Scatter Plot'; styleattrs datacolors=(blue lightyellow lightsalmon) datasymbols=(Asterisk Circlefilled Diamondfilled); scatter x=S y=M / group=A markeroutlineattrs=(color=black thickness=1) markerattrs=(color=blue); /* 显式指定星号颜色 */ run;
针对属性映射数据集的修改方案
把属性映射数据集中的fillcolor字段改为markercolor,适配非填充标记的颜色控制逻辑:
data mattrs; retain linecolor "black"; infile datalines truncover; input ID Value markersymbol markercolor; /* 将fillcolor替换为markercolor */ datalines; U N circlefilled lightyellow U R diamondfilled lightsalmon U S asterisk blue ; run; data unk; infile datalines truncover; input S $ Value $ M ID $; datalines; ZB N 3 U ZB R 5 U ZB S 10 U YQ N 11 U YQ R 6 U YQ S 7 U XI N 1 U XI R 5 U XI S 2 U TO N 9 U TO R 3 U TO S 10 U ; run; proc sgplot data=unk dattrmap=mattrs; scatter x=S y=M / group=Value attrid=U; yaxis min=0 max=100 type=log logstyle=logexpand logbase=10 grid; run;
内容的提问来源于stack exchange,提问作者DB5
相关产品推荐
相关产品推荐

