Last active
August 28, 2017 13:04
-
-
Save padpadpadpad/5670c65c3063155a5df657ae5c464baa to your computer and use it in GitHub Desktop.
Some visualisations of our footgolf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Footgolf scores | |
# packages | |
library(dplyr) | |
library(tidyr) | |
library(ggplot2) | |
library(ggjoy) | |
# Input data | |
footgolf <- data.frame(player = rep(c('George', 'Colin', 'Paddy', 'Silky'), each = 18), scores = c(4, 6, 4, 4, 5, 4, 2, 3, 5, 4, 4, 6, 3, 7, 5, 5, 5, 4, 3, 5, 5, 3, 3, 3, 3, 3, 6, 2, 4, 5, 3, 5, 4, 3, 5, 5, 4, 4, 5, 3, 3, 5, 4, 3, 4, 4, 5, 4, 3, 3, 4, 3, 7, 4, 4, 5, 5, 3, 2, 3, 4, 4, 6, 3, 4, 5, 3, 1, 5, 4, 3, 5), stringsAsFactors = FALSE) | |
# data transformations | |
footgolf <- mutate(footgolf, par = rep(c(3,3,5,3,3,4,3,3,4,3,3,5,3,3,4,3,3,4), times = 4), | |
score = scores - par) %>% | |
group_by(., player) %>% | |
mutate(., running_score = cumsum(scores), | |
hole = 1:18, | |
hole2 = rep(1:9, times = 2), | |
in_out = rep(c('front 9', 'back 9'), each = 9), | |
running_par = cumsum(par)) %>% | |
ungroup() | |
# How it was won | |
ggplot(footgolf) + | |
geom_line(aes(hole, running_score, col = player), size = 1.5) + | |
geom_line(aes(hole, running_par), linetype = 2) + | |
theme_bw(base_size = 14, base_family = 'Helvetica') + | |
xlab('Hole') + | |
ylab('Cumulative Score') + | |
ggtitle('How Silky won footgolf (cumulative score)') + | |
scale_color_discrete('') + | |
theme(legend.position = c(0.1, 0.85)) | |
# densities of scores by player | |
ggplot(footgolf) + | |
geom_joy(aes(x = scores, y = player, col = player, fill = player), alpha = 0.5) + | |
theme_bw(base_size = 14, base_family = 'Helvetica') + | |
xlab('Scores') + | |
ylab('Player') + | |
ggtitle('How Silky won footgolf (density of raw scores)') + | |
scale_color_discrete('') + | |
theme(legend.position = 'none') | |
# densities of scores by hole | |
ggplot(footgolf) + | |
geom_joy(aes(x = score, y = factor(hole2)), alpha = 0.5) + | |
theme_bw(base_size = 14, base_family = 'Helvetica') + | |
xlab('corrected score (score - par)') + | |
ylab('hole') + | |
ggtitle('What is the hardest hole?') + | |
scale_color_discrete('') + | |
theme(legend.position = 'none') | |
# desnities of scores by hole and time out | |
ggplot(footgolf) + | |
geom_joy(aes(x = score, y = factor(hole2), fill = in_out), alpha = 0.5) + | |
theme_bw(base_size = 14, base_family = 'Helvetica') + | |
xlab('corrected score (score - par)') + | |
ylab('hole') + | |
ggtitle('did we do better the second time round?') + | |
scale_fill_manual('', values = c('black', 'red')) + | |
theme(legend.position = 'right') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment