我想使用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;
当前输出:
我希望图例仅包含 A
和 B
各一个实例,并且符号位于图例中的行的顶部,因为它在剧情。我怎样才能做到这一点?
最佳答案
将标记添加到系列图中,然后仅使用该系列作为图例。
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;
它产生了这个,我认为这就是你想要的:
关于plot - 如何在 SGPLOT 图例中组合散点和系列线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29371773/