View source: R/geom_lm_pooled_indicator.R
geom_lm_indicator | R Documentation |
Drawing prediction interval for OLS linear model
geom_lm_indicator(
mapping = NULL,
data = NULL,
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = T,
...
)
... |
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.