SAS Gplot叠加线图
我试图在同一张图表上绘制两组折线图:SAS Gplot叠加线图,plot,sas,Plot,Sas,我试图在同一张图表上绘制两组折线图: /* make data */ data test ; do i = 1 to 2 ; do x = 1 to 5 ; y = i*x ; z = 0.5*i*x ; output; end ; end ; run ; data test ; set test ; if i =1 then y = -1*y ; if i =1 then z = -1*z ; run ; /* set gr
/* make data */
data test ;
do i = 1 to 2 ;
do x = 1 to 5 ;
y = i*x ;
z = 0.5*i*x ;
output;
end ;
end ;
run ;
data test ;
set test ;
if i =1 then y = -1*y ;
if i =1 then z = -1*z ;
run ;
/* set graph style */
* X axis *; axis1 order = (0 to 5 by 1)
label = ("x" h=1)
minor = (number=4)
value = (h=1)
offset = (0,0);
* Y axis *; axis2 label = ("y/z" j=c h=1)
minor = (number=1)
value = (h=1)
offset = (0,0);
symbol1 color=BL interpol=join width=1.25 value="" line=20;
symbol2 color=VIB interpol=join width=1.25 value="" line=1;
legend1 position=(top right inside)
value=("y" "z")
label=(position=top justify=center 'Var')
across=1;
/* plot */
proc gplot data=test;
plot y*x z*x / overlay noframe vaxis=axis2 haxis=axis1 autovref legend=legend1
cvref=ltgray autohref chref=ltgray lhref=33 lvref=33;
where i in (1,2) ;
run;
quit;
我可以毫无问题地绘制I=1或I=2的数据,但当我尝试在同一图表上绘制两个系列时,会出现两条额外的线(下面用绘制不好的箭头突出显示),它们将系列I=1的最后一个值与I=2的第一个值联系起来
如何防止这种情况发生?我利用
plot2
和分类语法y*x=I
提出了一个近似解决方案。IMHO(经过RTFM和技术论文搜索的广泛过程后),您最初的将所有图放入一个图形的请求不能简单地完成,因为
语句用于生成不同的图形by
- 分类语法
与绘图选项y*x=class_变量
不兼容。当它们共存时,将显示以下警告消息:/overlay
plot2
。因此,这里的解决方案仅限于
- 2个y轴变量(本例中为y&z)
- 分类变量(在本例中为i)的不同值的数量是无限的
/* make data */
data test ;
do i = 1 to 2 ;
do x = 1 to 5 ;
y = i * x ;
z = 0.5 * i * x ;
output;
end ;
end ;
run;
data test ;
set test ;
if i =1 then y = -1*y ;
if i =1 then z = -1*z ;
run ;
/* set graph style */
* X axis *; axis1 order = (0 to 5 by 1)
label = ("x" h=1)
minor = (number=4)
value = (h=1)
offset = (0,0);
* Y axis *; axis2 order = -5 to 10 by 1
label = ("y/z" j=c h=1)
minor = (number=1)
value = (h=1)
offset = (0,0);
* Y axis for plot2 (hidden, same scale as axis2) * ;
axis3 order = -5 to 10 by 1
label = (" ")
minor = none
major = none
value = none
offset = (0,0);
symbol1 color=BL interpol=join width=1.25 value="" line=20;
symbol2 color=VIB interpol=join width=1.25 value="" line=1;
/* legend changed */
legend1 position=(top right inside)
value=("i=1" "i=2")
label=(position=top justify=center 'y')
across=1;
/* extra settings added for plot2 */
symbol3 color=GREEN interpol=join width=1.25 value="" line=20;
symbol4 color=RED interpol=join width=1.25 value="" line=1;
legend2 position=(top left inside)
value=("i=1" "i=2")
label=(position=top justify=center 'z')
across=1;
/* plot */
proc gplot data=test;
plot y*x=i / noframe vaxis=axis2 haxis=axis1 autovref legend=legend1
cvref=ltgray autohref chref=ltgray lhref=33 lvref=33;
plot2 z*x=i / noframe vaxis=axis3 legend=legend2;
run;
quit;
谢谢将选项
color=ltgray style=33
添加到axis3参数会完全“隐藏”第二个y轴。