ggplot.lm: Method for plotting linear models

Description Usage Arguments Value Examples

View source: R/plot_functions.R

Description

Simple method to plot a linear model using ggplot along with 95

Usage

1
2
## S3 method for class 'lm'
ggplot(data, mapping, vars, ...)

Arguments

data

The linear model object from lm

mapping

Regular mapping, see ggplot and aes for details.

vars

A list of variable values used for prediction.

...

Additional arguments passed to ggplot

Value

A ggplot class object.

Examples

1
2
3
4
5
6
7
8
9
ggplot2::ggplot(
  lm(mpg ~ hp * qsec, data = mtcars),
  ggplot2::aes(hp, mpg, linetype = factor(qsec)),
  vars = list(
    hp = min(mtcars$hp):max(mtcars$hp),
    qsec = round(mean(mtcars$qsec) + c(-1, 1) * sd(mtcars$qsec)), 1)) +
  ggplot2::geom_ribbon(ggplot2::aes(ymin = LL, ymax = UL), alpha = .2) +
  ggplot2::geom_line() +
  ggplot2::theme_bw()

ElkhartGroup/AdvancedRPkg documentation built on May 6, 2019, 3:24 p.m.