Re: [R] Controlling the extent of ablines on plot

From: Duncan Murdoch <murdoch.duncan_at_gmail.com>
Date: Tue, 03 May 2011 14:02:01 -0400

On 03/05/2011 1:26 PM, Ryan Utz 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

Write your own abline. For example, with your previously posted example:

xlim <- c(0, 5)
ylim <- c(0, 10)

abline2 <- function(h, v) {

   if (!missing(h)) {

     n <- length(h)
     segments( rep(xlim[1], n), h, rep(xlim[2], n), h)
   }
   if (!missing(v)) {
     n <- length(v)
     segments( rep(ylim[1], n), v, rep(ylim[2], n), v)
   }
}

Just replace your abline() call with abline2().

Duncan Murdoch



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. Received on Thu 05 May 2011 - 06:25:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 05 May 2011 - 07:00:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive