Skip to content
Prev 258752 / 398503 Next

Controlling the extent of ablines on plot

Hi Ryan,

The issue is the plotting region is slightly padded.  The easiest
option, I think, would be to clip() it.  I have a general sense that
one of the par() options would let you adjust the padding to 0, but I
could just be imagining that (anyone else??).  Anyway, here are some
options:

###
plot(0:5, seq(0, 10, 2), axes=FALSE)
axis(1, at=c(0,1,2,2.5,3,4,5), pos=0)
axis(2, at=seq(0, 10, 2), pos=0)
## using clip and abline
clip(0, 5, 0, 10)
abline(h = 1:5)
dev.new()
plot(0:5, seq(0, 10, 2), axes=FALSE)
axis(1, at=c(0,1,2,2.5,3,4,5), pos=0)
axis(2, at=seq(0, 10, 2), pos=0)
## using lines, but without retyping as much
sapply(1:5, function(y) lines(c(0, 5), c(y, y)))
## or even easier, getting the same thing with segments
segments(0, 1:5, 5, 1:5)

HTH,

Josh
On Tue, May 3, 2011 at 10:26 AM, Ryan Utz <utz.ryan at gmail.com> wrote: