Skip to content

plot: abline() - define line length

4 messages · Remko Duursma, Jörg Groß, Greg Snow

#
Hi,

is there a way to define, that a line drawn via abline() should only  
go from for example -2 to 1 on the x-axis (with something working  
similiar to xlim()) ?

thanks for any help!
#
I use this function (a lot):

ablinepiece <- function(a=NULL,b=NULL,reg=NULL,from,to,...){

    # Borrowed from abline
    if (!is.null(reg)) a <- reg

    if (!is.null(a) && is.list(a)) {
            temp <- as.vector(coefficients(a))

        if (length(temp) == 1) {
            a <- 0
            b <- temp
        }
        else {
            a <- temp[1]
            b <- temp[2]
        }
    }

    segments(x0=from,x1=to,
             y0=a+from*b,y1=a+to*b,...)

}



-------------------------------------------------
Remko Duursma
Post-Doctoral Fellow

Centre for Plant and Food Science
University of Western Sydney
Hawkesbury Campus
Richmond NSW 2753

Dept of Biological Science
Macquarie University
North Ryde NSW 2109
Australia

Mobile: +61 (0)422 096908
On Thu, Jan 22, 2009 at 11:01 AM, J?rg Gro? <joerg at licht-malerei.de> wrote:
#
Thanks, that's great!



Am 22.01.2009 um 01:18 schrieb Remko Duursma:
#
Use either the 'clip' function from the graphics package, or the 'clipplot' function from the TeachingDemos package.

Hope this helps,