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

标签 plot sas legend scatter-plot line-plot

我想使用PROC SGPLOT作为散点图来呈现数据,误差线由一条线连接起来,并让图例使用scatter语句中的点和series 语句中的行。

以下是一些数据:

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;

当前输出:

enter image description here

我希望图例仅包含 AB 各一个实例,并且符号位于图例中的行的顶部,因为它在剧情。我怎样才能做到这一点?

最佳答案

将标记添加到系列图中,然后仅使用该系列作为图例。

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;

它产生了这个,我认为这就是你想要的: enter image description here

关于plot - 如何在 SGPLOT 图例中组合散点和系列线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29371773/

相关文章:

python多行为一组

r - 如何在基本 R 图中仅将一个图例名称设为斜体?

python - 如何将图例置于情节之外

具有透明背景的 R 绘图图例

matlab - 如何在 MATLAB 中使用不规则间隔的数据制作冲浪图?

r - 添加水平线,按因素分组

加法双向表 Tukey 图的 R 实现

sas - 使用 SAS 宏从 Windows 目录通过管道传输文件名列表

sas - 只保留重复项

email - 如何通过电子邮件从 SAS DIS 发布(csv、xlsx 等)文件