Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

regLine

Plot Regression Line


Description

Plots a regression line on a scatterplot; the line is plotted between the minimum and maximum x-values.

Usage

regLine(mod, col=carPalette()[2], lwd=2, lty=1,...)

Arguments

mod

a model, such as produced by lm, that responds to the coef function by returning a 2-element vector, whose elements are interpreted respectively as the intercept and slope of a regresison line.

col

color for points and lines; the default is the second entry in the current car palette (see carPalette and par).

lwd

line width; default is 2 (see par).

lty

line type; default is 1, a solid line (see par).

...

optional arguments to be passed to the lines plotting function.

Details

In contrast to abline, this function plots only over the range of the observed x-values. The x-values are extracted from mod as the second column of the model matrix.

Value

NULL. This function is used for its side effect: adding a line to the plot.

Author(s)

See Also

Examples

plot(repwt ~ weight, pch=c(1,2)[sex], data=Davis)
regLine(lm(repwt~weight, subset=sex=="M", data=Davis))
regLine(lm(repwt~weight, subset=sex=="F", data=Davis), lty=2)

car

Companion to Applied Regression

v3.0-10
GPL (>= 2)
Authors
John Fox [aut, cre], Sanford Weisberg [aut], Brad Price [aut], Daniel Adler [ctb], Douglas Bates [ctb], Gabriel Baud-Bovy [ctb], Ben Bolker [ctb], Steve Ellison [ctb], David Firth [ctb], Michael Friendly [ctb], Gregor Gorjanc [ctb], Spencer Graves [ctb], Richard Heiberger [ctb], Pavel Krivitsky [ctb], Rafael Laboissiere [ctb], Martin Maechler [ctb], Georges Monette [ctb], Duncan Murdoch [ctb], Henric Nilsson [ctb], Derek Ogle [ctb], Brian Ripley [ctb], William Venables [ctb], Steve Walker [ctb], David Winsemius [ctb], Achim Zeileis [ctb], R-Core [ctb]
Initial release
2020-09-23

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.