How to build abline value in R?

I used this code to create this graph:

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 build the meaning of the ablinks in a simple plot?

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

+5
source share
2 answers

to scale the graph so that the lines in the middle change the axis ie

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)

meaning "I assume that you mean where the line cuts the x axis? Something like text? that is :.

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

if you need a label on the x axis try:

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

to prevent a match between labels, you can remove the zero ie:

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

or before you draw the extension, add labels farther 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))
+6
source

, @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')

0

All Articles