gf_model_old: Old version of 'gf_model()'

View source: R/gf_model_old.R

gf_model_oldR Documentation

Old version of gf_model()

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 gf_lm(), with empty models gf_hline() using the mean, and a more complicated call to 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. Note: this function only works with models that have a single or NULL explanatory variable, and it will not work with multiple regression.

Usage

gf_model_old(
  object = NULL,
  gformula = NULL,
  data = NULL,
  model = NULL,
  width = 0.3,
  ...
)

Arguments

object

When chaining, this holds an object produced in the earlier portions of the chain. Most users can safely ignore this argument. See details and examples.

gformula

A formula with shape y ~ x. Superseded by model if one is given.

data

A data frame with the variables to be plotted. Superseded by model if one is given.

model

A model fit by lm(). If a model is given, it supersedes the data and gformula.

width

The width of the mean line(s) to be plotted for group models. Note that factors are plotted 1 unit apart, so values larger than 1 will overlap into other groups.

...

Arguments passed on to the respective ⁠gf_*⁠ function.

Value

A gg object

Examples

# basic examples
gf_model_old(Thumb ~ NULL, data = Fingers)
gf_model_old(Thumb ~ Height, data = Fingers)
gf_model_old(Thumb ~ RaceEthnic, data = Fingers)

# specifying the model using a fitted model
model <- lm(Thumb ~ Height, data = Fingers)
gf_model_old(model)

# chaining on to previous plots
gf_point(Thumb ~ Height, data = Fingers) %>%
  gf_model_old()

gf_point(Thumb ~ Height, data = Fingers) %>%
  gf_model_old() %>%
  gf_model_old(Thumb ~ NULL)

UCLATALL/coursekata-r documentation built on Aug. 24, 2023, 8:54 p.m.