Skip to content
Prev 205297 / 398506 Next

how to draw abline correctly?

aegea wrote:
Thanks for the nice example.

size=c(80, 40, 20, 16, 10, 8, 4, 2)
estimate=c(0.1353, 0.1337, 0.1237, 0.1164,  0.1058, 0.0983, 0.0759 , 0.0607)
plot(size, estimate, type="o", lwd=1.5, col="blue", ylim=c(0, 0.2),
xlim=c(0,80),pch=16)
abline(h=0.1361, col="red", lwd=1.5)
# use NA for no dot
legend(0, 0.2,c("method1","method2"), cex=0.8,    col=c("blue","red"),
pch=c(16,NA), lty=1);

# text inside it is easy
text(-0,0.134,"0.134",col="blue")
# outside you could use mtext, but not for exact position
mtext("0.134",2,adj=0.7,padj=-1,col="green")
# best is to plot another axis
#axis(2,0.134,"0.134") # ugly overprint
axis(2,0.134,"0.134",las=2,col="red")