Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot the value of abline in R?

Tags:

plot

r

I used this code to make this plot:

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))

My plot looks like this: Plot

1.) How can I plot the value of the ablines in a simple plot?

2.) How can I scale my plot so that both lines appear in the middle?

like image 904
Tunc Jamgocyan Avatar asked May 11 '12 11:05

Tunc Jamgocyan


1 Answers

to change scale of plot so lines are in the middle change the axes i.e.

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)

by "value" I am assuming you mean where the line cuts the x-axis? Something like text? i.e.:

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

if you want the label on the x axis then try:

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

to prevent overlap between labels you could remove the zero i.e.:

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

or before you plot extend the margins and add the labels further from the axis

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))
like image 155
user1317221_G Avatar answered Oct 07 '22 02:10

user1317221_G