|
|
@@ -1,7 +1,11 @@
|
|
|
# Analysis of foul data
|
|
|
library(tidyverse)
|
|
|
|
|
|
-allfouls <- read_csv("data/foulsonly.csv")
|
|
|
+datafiles <- list.files("data", pattern="*-allfouls.csv", full.names = FALSE)
|
|
|
+
|
|
|
+allfouls <- purrr::map_df(datafiles,
|
|
|
+ ~read_csv(paste0("data/", .x)),
|
|
|
+ .id = "filename")
|
|
|
|
|
|
## Plots
|
|
|
# histogram of fouls as a function of corrected score margin
|
|
|
@@ -11,7 +15,6 @@ ggplot(allfouls, aes(x=SCOREMARGIN_CORR)) +
|
|
|
theme_bw() +
|
|
|
scale_y_log10() +
|
|
|
xlab("Score Margin") + ylab("N Fouls")
|
|
|
-
|
|
|
dev.off()
|
|
|
|
|
|
# histogram of fouls as a function of corrected score margin,
|
|
|
@@ -31,10 +34,20 @@ dev.off()
|
|
|
|
|
|
# hexbin plots of fouls as a function of total score and corrected score
|
|
|
# margin, separated by home and away teams
|
|
|
-png('figures/fouls_totalscore-hexbin.png', height=600, width=1200)
|
|
|
+png('figures/fouls_totalscore-hexbin-byhomevisitor.png', height=600, width=1200)
|
|
|
ggplot(allfouls, aes(SCOREMARGIN_CORR, TOTALSCORE)) +
|
|
|
geom_hex() +
|
|
|
scale_fill_viridis_c() +
|
|
|
theme_bw() +
|
|
|
facet_wrap(vars(FOULTEAM))
|
|
|
dev.off()
|
|
|
+
|
|
|
+# hexbin plots of fouls as a function of total score and corrected score
|
|
|
+# margin, separated by season
|
|
|
+png('figures/fouls_totalscore-hexbin-byseason.png', height=1200, width=1200)
|
|
|
+ggplot(allfouls, aes(SCOREMARGIN_CORR, TOTALSCORE)) +
|
|
|
+ geom_hex() +
|
|
|
+ scale_fill_viridis_c() +
|
|
|
+ theme_bw() +
|
|
|
+ facet_wrap(vars(filename))
|
|
|
+dev.off()
|