如何在 SGPLOT 的图例中组合散点和系列线?

How can I combine a scatter point and a series line in the legend of SGPLOT?

我想使用 PROC SGPLOT 作为散点图呈现数据,误差线由一条线连接,图例使用 scatter 语句中的点和 scatter 中的线=14=]声明。

以下是一些数据:

data dat;
  input x y high low grp $;
  cards;
1 2.50 2.90 2.00 A
2 1.90 2.35 1.45 A
3 1.75 2.25 1.25 A
1 2.10 2.50 1.70 B
2 2.00 2.40 1.60 B
3 1.80 2.20 1.40 B
;
run;

我要调整的代码:

proc sgplot data=dat;
  scatter x=x y=y / yerrorupper=high yerrorlower=low group=grp
                    groupdisplay=cluster clusterwidth=0.1
                    markerattrs=(size=7 symbol=circlefilled);
  series x=x y=y / group=grp groupdisplay=cluster clusterwidth=0.1;
  xaxis label='Time' values=(1,2,3);
  yaxis label='Response' min=0 max=3.5;
  keylegend / location=inside position=topright title="Group";
run;

当前输出:

我希望图例仅包含 AB 中的每个实例,并且符号位于图例中线条的顶部,就像在图中一样。我该怎么做?

将标记添加到 SERIES 图中,然后仅将系列用于图例。

proc sgplot data=dat;
  scatter x=x y=y / yerrorupper=high yerrorlower=low group=grp
                    groupdisplay=cluster clusterwidth=0.1
                    name="scatter";
  series x=x y=y / markers markerattrs=(size=7 symbol=circlefilled)
                   group=grp groupdisplay=cluster clusterwidth=0.1 name="series";
  xaxis label='Time' values=(1,2,3);
  yaxis label='Response' min=0 max=3.5;
  keylegend "series" / location=inside position=topright title="Group";
run;

它产生了这个,我想这就是你想要的: