Skip to content

Instantly share code, notes, and snippets.

@homerhanumat
Created April 12, 2018 18:52
Show Gist options
  • Save homerhanumat/bb8cb78631ee19c846cf24142231e02f to your computer and use it in GitHub Desktop.
Save homerhanumat/bb8cb78631ee19c846cf24142231e02f to your computer and use it in GitHub Desktop.
ggplot illustration for k. kendall
library(tidyverse)
xVals <- function(n, center, width) {
seq(from = center - width, to = center + width, length.out = n)
}
width <- 0.3
survey <- tigerstats::m111survey
gms <-
survey %>%
group_by(seat) %>%
summarize(groupMean = mean(fastest), n = n()) %>%
mutate(grpNumber = as.numeric(seat)) %>%
mutate(xStart = grpNumber - width,
xEnd = grpNumber + width)
xs <- c(xVals(gms$n[1], 1, width),
xVals(gms$n[2], 2, width),
xVals(gms$n[3], 3, width))
survey <-
survey %>%
inner_join(gms, by = "seat") %>%
mutate(grandMean = mean(fastest)) %>%
arrange(seat) %>%
mutate(xs = xs)
# SSE
ggplot(survey, aes(x = xs, y = fastest)) +
geom_point() +
geom_segment(aes(x = xs, y = fastest, xend = xs, yend = groupMean)) +
geom_segment(gms,
mapping = aes(x = xStart, xend = xEnd, y = groupMean, yend = groupMean))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment