You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PROC SGPLOT中为特定分组变量设置虚线样式?

实现SAS SGPLOT中指定分组的虚线样式

原始代码

proc sgplot data=via_in04;

xaxis label=" ";
yaxis label=" ";

styleattrs
dataconstrastcolors=(grlg black red blue skyblue orange green);

series x=rq_pt y=count_time / datalabel
group=newgroup lineattrs=(thickness=3);

run;

问题需求

希望仅将newgroup中某个特定分组对应的图形显示为虚线,但lineattrs会统一应用于所有分组,无法单独修改单个分组样式。

解决方案

可以通过拆分多个series语句分别处理不同分组,给目标分组单独设置虚线样式:

假设你要设置为虚线的分组值是'TargetGroup'(替换成你实际的分组值),修改后的代码如下:

proc sgplot data=via_in04;
    xaxis label=" ";
    yaxis label=" ";

    styleattrs dataconstrastcolors=(grlg black red blue skyblue orange green);

    /* 绘制所有非目标分组,使用实线 */
    series x=rq_pt y=count_time / datalabel 
           group=newgroup(where=(newgroup ne 'TargetGroup')) 
           lineattrs=(thickness=3);

    /* 绘制目标分组,使用虚线 */
    series x=rq_pt y=count_time / datalabel 
           group=newgroup(where=(newgroup eq 'TargetGroup')) 
           lineattrs=(thickness=3 linestyle=dash);
run;

这种方法可以精准控制任意分组的样式,不受全局lineattrs的限制,同时保留原有的颜色设置和数据标签。


内容的提问来源于stack exchange,提问作者overbold

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 22:52:40