R fitting text on abline

plot, r

Solution

Here's mine, it should scale to the slope and scale of the graph:

x1<-1:10 
y1<-10:1

a<-0
b<-0.2
plot(x1,y1)
abline(a,b)
text(mean(x1),(b*max(x1)/2+a),"text",srt=0.2,pos=3)

The argument `pos=3` denotes that the text should be offset above the point you specify, and the `x` and `y` arguments in plot are just the middle x point on the line.

Edit: Setting `srt=b*45` will rotate your text along the line, but mamy be fidgety for smaller scaled plots.

Problem

I want to place a text string on an fx. abline(0,0.2) But data is changing in scale (fx. 0,01-1 and 5-2000) in my for loop, so how to control the position of the text so it always sits nicely on the abline in the plot? (without the loop): ``` #example data row 1 x1<-1:10 y1<-10:1 plot(x1,y1) abline(0,0.2) text(?,?,"text",srt=0.2) ```

Original source