[R] Controlling the extent of ablines on plot

Joshua Wiley jwiley.psych at gmail.com
Tue May 3 19:40:47 CEST 2011


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:
> Well... that could work. Problem is in the actual graphs I'm making, there
> are to be >30 lines per graph (as many as 60 in some cases). Any way I could
> use the lines command without having to write out 60 lines of code per
> figure? That's why I like ablines; you just have to specify a single value
> and it will put a horizontal line at that number.
>
> Thanks,
> Ryan
>
>
>> Maybe you could use lines()?
>>
>> plot(1:2)
>> lines(c(1,2),c(1.5,1.5))
>>
>>
>>
>
>
> --
>
> Ryan Utz, Ph.D.
> Aquatic Ecologist/STREON Scientist
> National Ecological Observatory Network
>
> Home/Cell: (724) 272-7769
> Work: (720) 746-4844 ext. 2488
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list