ab: Generate arguments to plot a line

View source: R/ab.R

abR Documentation

Generate arguments to plot a line

Description

Generate arguments to plot a line via abline.

Usage

ab(p1, p2)

Arguments

p1

first point

p2

second point

Value

A list with suitable named arguments for abline

v

For a horizontal line

a, b

intercept and slope

Author(s)

Georges Monette

See Also

abline, abline2

Examples

##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function( p1, p2 ) {
       # prepare arguments to plot a line with
       # do.call('abline', ab( p1, p2))
       d <- p2 - p1
       if ( d[1] == 0) {
          ret <- list( v = p1[1])
       }
       else {
          b = (p2[2]-p1[2])/(p2[1]-p1[1])
          ret <- list( a = p2[2] - b*p2[1], b =b)
       }
       ret
    }

gmonette/p3d documentation built on Nov. 16, 2023, 11:31 p.m.