#' compute_group_ols_ind <- function(data, scales) {
#'
#' model <- lm(y ~ x + indicator,
#' data = data)
#'
#' data.frame(x = data$x,
#' y = model$fitted.values,#,
#' indicator = data$indicator
#' )
#' }
#'
#' #### confint #####
#'
#'
#'
#' # For most applications the grouping is set implicitly by mapping one
#' # or more discrete variables to x, y, colour, fill, alpha, shape, size, and/or linetype
#'
#' StatOlsindicator1 <- ggplot2::ggproto("StatOlsindicator1",
#' ggplot2::Stat,
#' compute_panel = compute_group_ols_ind,
#' required_aes = c("x", "y", "indicator"),
#' default_aes = aes(group = after_stat(indicator))
#'
#' )
#'
#'
#'
#' geom_lm_indicator1 <- function(mapping = NULL, data = NULL,
#' position = "identity", na.rm = FALSE,
#' show.legend = NA,
#' inherit.aes = TRUE, ...) {
#' ggplot2::layer(
#' stat = StatOlsindicator1, geom = ggplot2::GeomLine, data = data, mapping = mapping,
#' position = position, show.legend = show.legend, inherit.aes = inherit.aes,
#' params = list(na.rm = na.rm, ...)
#' )
#' }
#'
#' library(tidyverse)
#' starwars %>%
#' filter(mass < 1000) %>%
#' mutate(sex_numeric = sex) %>%
#' ggplot() +
#' aes(x = height, y = mass, indicator = sex) +
#' geom_point(aes(color = sex)) +
#' geom_lm_indicator1(linetype = "dashed")
#' # geom_lm_indicator1 <- function(mapping = NULL, data = NULL,#
#' #' Drawing prediction interval for OLS linear model
#' #'
#' #' @param mapping
#' #' @param data
#' #' @param position
#' #' @param na.rm
#' #' @param show.legend
#' #' @param inherit.aes
#' #' @param ...
#' #'
#' #' @return
#' #' @export
#' #'
#' #' @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 = my_data$mass,
#' #' yfit = model$fitted.values,
#' #' group = my_data$sex) %>%
#' #' ggplot() +
#' #' aes(x = x, y = y, group = group) +
#' #' geom_point(aes(color = group, alpha = group == "none")) +
#' #' geom_line(aes(y = yfit))
#' #'
#' #' starwars %>%
#' #' filter(mass < 1000) %>%
#' #' mutate(sex_numeric = sex) %>%
#' #' ggplot() +
#' #' aes(x = height, y = mass) +
#' #' #geom_point(aes(color = sex)) +
#' #' geom_lm_indicator1(linetype = "dashed")
#' # geom_lm_indicator1 <- function(mapping = NULL, data = NULL,# position = "identity", na.rm = FALSE, show.legend = NA,# inherit.aes = T, ...) {# ggplot2::layer(# stat = StatOlsindicator1, geom = ggplot2::GeomLine, data = data, mapping = mapping,# position = position, show.legend = show.legend, inherit.aes = inherit.aes,# params = list(na.rm = na.rm, ...)# )# }
#'
#'
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.