Intro Thoughts

Status Quo

library(tidyverse)

Experiment

mtcars |>
  ggplot(aes(wt, mpg)) +
  geom_point() +
  geom_smooth(method = lm) +
  stat_smooth(method = lm,
              geom = "point", # draw fitted values as points
              color = "blue",
              xseq = c(3,4),
              size = 3)
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'

layer_data(last_plot(), 3)
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
##   x        y     ymin     ymax        se flipped_aes PANEL group shape colour
## 1 3 21.25171 20.12444 22.37899 0.5519713       FALSE     1    -1    19   blue
## 2 4 15.90724 14.49018 17.32429 0.6938618       FALSE     1    -1    19   blue
##   size fill alpha stroke
## 1    3   NA    NA    0.5
## 2    3   NA    NA    0.5
xdiff <- c(2,3)

mtcars |>
  ggplot(aes(wt, mpg)) +
  geom_point() +
  geom_smooth(method = lm) +
  stat_smooth(method = lm, 
              geom = 'point',
              xseq = c(2,3), 
              size = 3, 
              color = "blue") +
  stat_smooth(method = lm,
              geom = "segment", # draw fitted values as points
              color = "darkred",
              xseq = c(2,3), # 'from', 'to' value pair
              aes(yend = after_stat(y[1]), # 'from' value of y
                  xend = 3), # 'to' value of x
              arrow = arrow(ends = c("last", "first"), 
                            length = unit(.1, "in"))) 
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'

std <- function(x){
  
  (x - mean(x))/sd(x)
  
}

mtcars |>
  ggplot() +
  aes(std(wt), std(mpg)) +
  geom_point() +
  geom_smooth(method = lm) +
  stat_smooth(method = lm, 
              geom = 'point',
              xseq = c(0,1), 
              size = 3, 
              color = "blue") +
  stat_smooth(method = lm,
              geom = "segment", # draw fitted values as points
              color = "darkred",
              xseq = c(0,1), # 'from', 'to' value pair
              aes(yend = after_stat(y[1]), # 'from' value of y
                  xend = 1), # 'to' value of x
              arrow = arrow(ends = c("last", "first"), 
                            length = unit(.1, "in"))) + 
  coord_fixed() + 
  annotate(geom = "point",
           x = 0, y = 0,
           shape = 4,
           size = 200,
           alpha = .3)
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'

readLines("https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/mtcars.html") %>% cat()

Closing remarks, Other Relevant Work, Caveats