add_curve: Add a fitted linear model to a plot

View source: R/add_curve.R

add_curveR Documentation

Add a fitted linear model to a plot

Description

Include a line or curve created from a linear model with a single response and a single explanatory variable. The mod function should be created by using the lm function. To plot a polynomial curve, use the poly function with the explanatory variable. See the examples below for additional usage details.

Usage

add_curve(mod, col = "black", plot_base = trellis.last.object())

Arguments

mod

Model. A linear model with a single response and a single explanatory variable.

col

Character. The name of a color to use when plotting the line/curve.

See Also

add_line, lm, poly

Examples

# Create a linear model and use the model plot the line on a xyplot
m_line <- lm(weight ~ height, data = cdc)
xyplot(weight ~ height, data = cdc)
add_curve(m_line)

# Create a linear model with a quadratic polynomial and include the curve on
# the xyplot.
m_curve <- lm(weight ~ poly(height, 2), data = cdc)
xyplot(weight ~ height, data = cdc)
add_curve(m_curve)


mobilizingcs/mobilizr documentation built on Feb. 17, 2024, 7:49 p.m.