add_regres_line: Add a regression line and confidence band to a plot

Description Usage Arguments Examples

View source: R/add_regres_line.R

Description

Plots a regression line from a simple linear model (of the form lm(y ~ x)) to a plot. Also plots the confidence band for the mean, which is calculated using predict.lm.

Usage

1
2
add_regres_line(fit, from = NULL, to = NULL, band = TRUE,
  ci.col = "#BEBEBEB3", ...)

Arguments

fit

Object returned by lm. Only models of the form y ~ x are supported, without expressions in I() (see Examples), or interactions, or multiple variables.

from

Optional (read from fitted model); Draw from this X value.

to

Optional (read from fitted model); Draw to this x value.

band

Logical. Whether to add a confidence band.

ci.col

Colour of the confidence band, if plotted. Defaults to a transparent grey colour.

...

Further arguments passed to abline_range

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#'Add a line across the range of the data from a regression object
with(mtcars, plot(1/wt, mpg, xlim=c(0,0.8), ylim=c(0,40)))

# add_regres_line does not allow I() expressions; yet.
mtcars$inv_wt <- 1 / mtcars$wt
fit <- lm(mpg ~ inv_wt, data=mtcars)
add_regres_line(fit)

# Add the regression line and confidence band behind the data
fit <- lm(height ~ age, data=Loblolly)
with(Loblolly, plot(age, height, pch=19, panel.first=add_regres_line(fit)))

RemkoDuursma/nlshelper documentation built on Nov. 29, 2017, 1:13 a.m.