2012-05-11 57 views
5

我用这个代码,以使该地块:如何绘制R中abline的值?

plot(p, cv2,col=rgb(0,100,0,50,maxColorValue=255),pch=16, 
    panel.last=abline(h=67,v=1.89, lty=1,lwd=3)) 

我的情节是这样的: Plot

1)如何可以绘制在一个简单的情节ablines的价值?

2.)我该如何缩放我的情节,使两条线都出现在中间?

+0

通过abline的价值,你是什么意思?任何示例代码? –

+0

是的,这就是我的意思! –

+0

不,我不知道您的价值是什么意思 –

回答

6

改变剧情的规模,使线在中间变化的轴即

x<-1:10 
y<-1:10 
plot(x,y) 
abline(a=1,b=0,v=1) 

changed to: 

x<-1:10 
y<-1:10 
plot(x,y,xlim=c(-30,30)) 
abline(a=1,b=0,v=1) 

通过“价值”我假设你的意思是,其中线切割线x轴?像text?即:

text((0), min(y), "number", pos=2) 

,如果你想在x轴上的标签,然后尝试:

abline(a=1,b=0,v=1) 
axis(1, at=1,labels=1) 

,以防止标签之间的重叠,你可以删除零即:

plot(x,y,xlim=c(-30,30),yaxt="n") 
axis(2, at=c(1.77,5,10,15,20,25)) 

,或者你之前绘图扩展边距并在轴线上添加标签

par(mar = c(6.5, 6.5, 6.5, 6.5)) 
plot(x,y,xlim=c(-30,30)) 
abline(a=1,b=0,v=1) 
axis(2, at=1.77,labels=1.77,mgp = c(10, 2, 0)) 
+0

这是我的方法: > plot(x,y,col = rgb(0,100,0,50,maxColorValue = 255), (2,las = 1) > axis(2)其中,pch = 16,panel.last = abline(h = 0.78,v = 1.77,lty = 1,lwd = 3),yaxt =“n” ,0.78,0.78,las = 1) >轴(1,1.77,1.70,77) 导致下面的图片: [图文](http://i.imgur.com/xdPkW.png) 可以看到,0.49和0重叠......我怎样才能解决这个问题他们不重叠? –

+0

举了两个例子 –

0

的精神,通过@ user1317221提出的答案相似,这里是我的建议

# generate some fake points 
x <- rnorm(100) 
y <- rnorm(100) 

# positions of the lines 
vert = 0.5 
horiz = 1.3 

要在图的中心显示线,首先计算数据点与线之间的水平和垂直距离,然后充分调整极限。现在

# compute the limits, in order for the lines to be centered 
# REM we add a small fraction (here 10%) to leave some empty space, 
# available to plot the values inside the frame (useful for one the solutions, see below) 
xlim = vert + c(-1.1, 1.1) * max(abs(x-vert)) 
ylim = horiz + c(-1.1, 1.1) * max(abs(y-horiz)) 

# do the main plotting 
plot(x, y, xlim=xlim, ylim=ylim) 
abline(h=horiz, v=vert) 

,可以绘制“线”的值,或者在轴(line参数,可以控制为可能重叠的):

mtext(c(vert, horiz), side=c(1,2)) 
绘图帧内

或替代地:

text(x=vert, y=ylim[1], labels=vert, adj=c(1.1,1), col='blue') 
text(x=xlim[1], y=horiz, labels=horiz, adj=c(0.9,-0.1), col='blue') 

HTH