geom_lm_indicator: Drawing prediction interval for OLS linear model

View source: R/geom_lm_pooled_indicator.R

geom_lm_indicatorR Documentation

Drawing prediction interval for OLS linear model

Description

Drawing prediction interval for OLS linear model

Usage

geom_lm_indicator(
  mapping = NULL,
  data = NULL,
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = T,
  ...
)

Arguments

...

Examples

library(ggplot2)
library(dplyr)
library(magrittr)

starwars %>%
   filter(mass < 1000) %>%
   tidyr::drop_na(mass, height, sex) ->
 my_data

 my_data %>%
   lm(mass ~ height + sex, data = .) ->
 model

data.frame(x = my_data$height,
y = model$fitted.values,
group = my_data$sex) %>%
ggplot() +
aes(x = x, y = y, group = group) +
geom_point() +
geom_line()

starwars %>%
filter(mass < 1000) %>%
mutate(sex_numeric = sex %>% as.factor() %>% as.numeric())  %>%
ggplot() +
aes(x = height, y = mass, indicator_as_numeric = sex_numeric) +
geom_point(aes(color = sex)) + geom_lm_indicator(linetype = "dashed")

EvaMaeRey/ggxmean documentation built on April 10, 2024, 6:32 p.m.