Last active
August 19, 2018 01:47
-
-
Save kevinsoo/ac6f9575f719bcfe544e21bb5c2c116e to your computer and use it in GitHub Desktop.
Script to randomize and visualize draft order for Fantasy Football League
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
| #### Load stuff | |
| library(tidyverse) | |
| library(gganimate) | |
| #### Generate data | |
| n <- 20 # Number of iterations/steps | |
| # Random walk for 4 players, add players as needed | |
| df <- tibble( | |
| ite = 0:n, | |
| Player1 = c(0, rnorm(n, mean = 1)), | |
| Player2 = c(0, rnorm(n, mean = 1)), | |
| Player3 = c(0, rnorm(n, mean = 1)), | |
| Player4 = c(0, rnorm(n, mean = 1))) %>% | |
| gather(player, score, Player1:Player4) %>% | |
| arrange(player, ite) %>% | |
| group_by(player) %>% | |
| mutate(totalScore = cumsum(score), | |
| size = ifelse(ite == n, 6, 4)) # This is used to size the labels | |
| #### Plot data | |
| ggplot(df, aes(x = player, y = totalScore)) + | |
| geom_hline(yintercept = 0, linetype ="dashed") + | |
| geom_label(aes(label = player, fill = player, size = size)) + | |
| theme_minimal() + | |
| theme(legend.position = 'none') + | |
| scale_fill_brewer(palette = "Spectral") + | |
| labs(title = "Random walk race", | |
| subtitle = "Iteration: {closest_state} of 20", | |
| y = "Score total", | |
| x = "Entity", | |
| caption = "Random walk simulated for 20 iterations") + | |
| transition_states(ite, transition_length = 1, state_length = 1, wrap = FALSE) + | |
| ease_aes('linear') + | |
| shadow_wake(wake_length = .1, wrap = FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment