Created
March 13, 2020 16:49
-
-
Save randomtestfive/b4279795ea07dde6c692c27ffbf38086 to your computer and use it in GitHub Desktop.
create charts for blog post
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
| library(tidyverse) | |
| library(shadowtext) | |
| library(ggplot2) | |
| winrate = read.csv("winrates.csv", header=F) | |
| everything = read.csv("big_scrape.csv") | |
| hlteams = everything %>% filter(team == "frc254" | team == "frc1741" | team == "frc6372" | team == "frc558" | team == "frc3933") | |
| ggplot(everything) + | |
| geom_histogram(aes(x=winrate, color=(team=="frc254")), bins=31, fill="black") + | |
| scale_color_manual(values=c("#ffffff","#0000ff")) + | |
| guides(color=F) + | |
| labs(x="Winrate", y="Count") | |
| ggplot(everything, aes(x=score, y=winrate)) + | |
| geom_point(alpha=0.3) + | |
| geom_shadowtext(data=hlteams, aes(label=team), hjust=0.5, vjust=1.5, size=5) + | |
| geom_point(data=hlteams, aes(x=score, y=winrate), color='red', size=3) + | |
| labs(x="Score", y="Winrate") | |
| ggplot(everything, aes(x=scorediff, y=winrate)) + | |
| geom_point(alpha=0.3) + | |
| geom_shadowtext(data=hlteams, aes(label=team), hjust=0.5, vjust=1.5, size=5) + | |
| geom_point(data=hlteams, aes(x=scorediff, y=winrate), color='red', size=3) + | |
| labs(x="Score Difference", y="Winrate") | |
| ggplot(everything, aes(x=scorediff, y=seed)) + | |
| geom_point(alpha=0.3) + | |
| geom_shadowtext(data=hlteams, aes(label=team), hjust=0.5, vjust=-0.5, size=5) + | |
| geom_point(data=hlteams, aes(x=scorediff, y=seed), color='red', size=3) + | |
| labs(x="Score Difference", y="Seed") | |
| ggplot(everything, aes(x=score, y=oppscore)) + | |
| geom_point(alpha=0.3) + | |
| scale_x_continuous(breaks=c(100,150,200,250,300,350,400,450)) + | |
| scale_y_continuous(breaks=c(100,150,200,250,300,350,400,450)) + | |
| expand_limits(x = 125, y = 125) + | |
| coord_fixed() + | |
| geom_abline(slope=1, color="blue", size=1, linetype="dotted") + | |
| geom_shadowtext(data=hlteams, aes(label=team), hjust=1, vjust=1.5, size=5) + | |
| geom_point(data=hlteams, aes(x=score, y=oppscore), color='red', size=3) + | |
| labs(x="Score", y="Opposing Score") | |
| #how many teams scored less than how much 254 beat teams by | |
| beat = everything %>% filter(score < hlteams[1,]$scorediff) %>% tally() | |
| beat_percent=beat/dim(everything)[1] | |
| times = read.csv("times.csv") | |
| teams = split(times, times$team) | |
| ggplot(times) + | |
| geom_histogram(aes(x=switch, fill=team)) + | |
| guides(fill=F) + | |
| facet_wrap(~team) + | |
| geom_vline(xintercept = 15) + | |
| geom_vline(xintercept = 150) + | |
| labs(x="Time (seconds)", y="Count") | |
| ggplot(times) + | |
| geom_histogram(aes(x=scale, fill=team)) + | |
| guides(fill=F) + | |
| facet_wrap(~team) + | |
| geom_vline(xintercept = 15) + | |
| geom_vline(xintercept = 150) + | |
| labs(x="Time (seconds)", y="Count") | |
| avgs <- times %>% | |
| group_by(team) %>% | |
| summarise_at(vars(rn_switch, r_scale, rf_switch), mean) | |
| ggplot(times) + | |
| geom_histogram(aes(x=rn_switch, fill=team)) + | |
| scale_y_continuous(breaks=c(0,8,16,24)) + | |
| scale_x_continuous(breaks=c(0,0.25,0.5,0.75,1), limits=c(0,1)) + | |
| guides(fill=F) + | |
| facet_wrap(~team) + | |
| geom_vline(data=avgs, aes(xintercept=rn_switch)) + | |
| geom_text(data=avgs, aes(x=rn_switch+ifelse(rn_switch < 0.5, 0.15, -0.15), | |
| label=paste("bar(x)==", round(rn_switch, digits=2))), | |
| y = 14, parse=T) + | |
| labs(x="Time (seconds)", y="Count") | |
| ggplot(times) + | |
| geom_histogram(aes(x=r_scale, fill=team)) + | |
| scale_y_continuous(breaks=c(0,4,8,12,16)) + | |
| scale_x_continuous(breaks=c(0,0.25,0.5,0.75,1), limits=c(0,1)) + | |
| guides(fill=F) + | |
| facet_wrap(~team) + | |
| geom_vline(data=avgs, aes(xintercept=r_scale)) + | |
| geom_text(data=avgs, aes(x=r_scale+ifelse(r_scale < 0.5, 0.15, -0.15), | |
| label=paste("bar(x)==", round(r_scale, digits=2))), | |
| y = 7, parse=T) + | |
| labs(x="Time (seconds)", y="Count") | |
| ggplot(times) + | |
| geom_histogram(aes(x=rf_switch, fill=team)) + | |
| scale_y_continuous(breaks=c(0,2,4,6,8,10)) + | |
| scale_x_continuous(breaks=c(0,0.25,0.5,0.75,1), limits=c(0,1)) + | |
| guides(fill=F) + | |
| facet_wrap(~team) + | |
| geom_vline(data=avgs, aes(xintercept=rf_switch)) + | |
| geom_text(data=avgs, aes(x=rf_switch+ifelse(rf_switch < 0.5, 0.15, -0.15), | |
| label=paste("bar(x)==", round(rf_switch, digits=2))), | |
| y = 5.5, parse=T) + | |
| labs(x="Time (seconds)", y="Count") | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where these were used