gf_model: Add a model to a plot

View source: R/gf_model.R

gf_modelR Documentation

Add a model to a plot

Description

When teaching about regression it can be useful to visualize the data as a point plot with the outcome on the y-axis and the explanatory variable on the x-axis. For regression models, this is most easily achieved by calling ggformula::gf_lm(), with empty models ggformula::gf_hline() using the mean, and a more complicated call to ggformula::gf_segment() for group models. This function simplifies this by making a guess about what kind of model you are plotting (empty/null, regression, group) and then making the appropriate plot layer for it.

Usage

gf_model(object, model, ...)

Arguments

object

A plot created with the ggformula package.

model

A linear model fit by either lm() or aov().

...

Additional arguments. Typically these are (a) ggplot2 aesthetics to be set with attribute = value, (b) ggplot2 aesthetics to be mapped with attribute = ~ expression, or (c) attributes of the layer as a whole, which are set with attribute = value.

Details

This function only works with models that have a continuous outcome measure.

Value

a gg object (a plot layer) that can be added to a plot.


coursekata documentation built on Sept. 11, 2024, 8:42 p.m.