Guest User

Untitled

a guest
Apr 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. library(tidyverse)
  2.  
  3. xVals <- function(n, center, width) {
  4. seq(from = center - width, to = center + width, length.out = n)
  5. }
  6. width <- 0.3
  7. survey <- tigerstats::m111survey
  8. gms <-
  9. survey %>%
  10. group_by(seat) %>%
  11. summarize(groupMean = mean(fastest), n = n()) %>%
  12. mutate(grpNumber = as.numeric(seat)) %>%
  13. mutate(xStart = grpNumber - width,
  14. xEnd = grpNumber + width)
  15.  
  16. xs <- c(xVals(gms$n[1], 1, width),
  17. xVals(gms$n[2], 2, width),
  18. xVals(gms$n[3], 3, width))
  19.  
  20. survey <-
  21. survey %>%
  22. inner_join(gms, by = "seat") %>%
  23. mutate(grandMean = mean(fastest)) %>%
  24. arrange(seat) %>%
  25. mutate(xs = xs)
  26.  
  27. # SSE
  28. ggplot(survey, aes(x = xs, y = fastest)) +
  29. geom_point() +
  30. geom_segment(aes(x = xs, y = fastest, xend = xs, yend = groupMean)) +
  31. geom_segment(gms,
  32. mapping = aes(x = xStart, xend = xEnd, y = groupMean, yend = groupMean))
Add Comment
Please, Sign In to add comment