-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunexpected_points.Rmd
123 lines (103 loc) · 3.57 KB
/
unexpected_points.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
---
title: "Unexpected Points"
output: html_notebook
---
This notebook reads in the data from the Unexpected Points Substack.
```{r libraries, include=TRUE, warning=FALSE, message=FALSE}
library(tidyverse)
library(googlesheets4)
library(nflverse)
library(gt)
library(gtExtras)
library(ggtext)
library(ggrepel)
library(patchwork)
library(ggimage)
```
```{r nfl_analytics_theme, include=TRUE}
nfl_analytics_theme <- function(..., base_size = 12) {
theme(
text = element_text(family = "Lexend",
size = base_size,
color = "black"),
axis.ticks = element_blank(),
axis.title = element_text(face = "bold"),
axis.text = element_text(face = "bold"),
plot.title.position = "plot",
plot.title = element_markdown(size = 16,
vjust = .02,
hjust = 0.5),
plot.subtitle = element_markdown(hjust = 0.5),
plot.caption = element_markdown(size = 8),
panel.grid.minor = element_blank(),
panel.grid.major = element_line(color = "#d0d0d0"),
panel.background = element_rect(fill = "#f7f7f7"),
plot.background = element_rect(fill = "#f7f7f7"),
panel.border = element_blank(),
legend.background = element_rect(color = "#F7F7F7"),
legend.key = element_rect(color = "#F7F7F7"),
legend.title = element_text(face = "bold"),
legend.title.align = 0.5,
strip.text = element_text(face = "bold"))
}
```
```{r teams, include=TRUE}
teams <- nflreadr::load_teams(current = TRUE)
```
```{r df_aqe, include=TRUE}
df_aqe <- read_sheet('https://docs.google.com/spreadsheets/d/1ktlf_ekms7aI6r0tF_HeX0zaxps-bHWYsgglUReC558/edit?gid=1212845642#gid=1212845642',
sheet = 'Adjusted Quarterback Efficiency')
df_aqe %>%
filter(plays > 100,
season == 2024)
```
```{r}
df_aqe %>%
filter(season == 2024) %>%
arrange(epa_rank)
```
```{r play_by_play_2024, include=TRUE}
play_by_play_2024 <- nflreadr::load_pbp(seasons = most_recent_season())
```
From Congelio:
> In the case of Roethlisberger, the three pass attempt difference was the result of the passer_player_name grouping including three QB spikes in the data. **Aside from when attempting to replicate the official statistics, it is better to use just passer as it removes those instances where a QB spike, scramble, or sack my skew the results of your data.**
```{r}
play_by_play_2024 %>%
filter(!is.na(passer)) %>%
group_by(passer) %>%
summarise(qb_epa = sum(qb_epa, na.rm = TRUE),
plays = n(),
.groups = 'drop') %>%
mutate(qb_epa_per = qb_epa / plays,
epa_rank = rank(-qb_epa)) %>%
arrange(-qb_epa)
```
```{r}
df_aqe %>%
filter(name == 'R.Wilson',
season == 2024)
```
```{r}
play_by_play_2024 %>%
# select(contains('epa'))
filter(game_id == '2024_07_NYJ_PIT',
play_type == 'pass') %>%
group_by(passer) %>%
summarise(sum_epa = sum(epa, na.rm = TRUE),
sum_epa_qb = sum(qb_epa, na.rm = TRUE),
sum_epa_yac = sum(yac_epa, na.rm = TRUE),
sum_epa_air = sum(air_epa, na.rm = TRUE),
sum_epa_comp_yac = sum(comp_yac_epa, na.rm = TRUE),
sum_epa_xyac = sum(xyac_epa, na.rm = TRUE),
plays = n(),
.groups = 'drop') %>%
mutate(test = sum_epa_air + sum_epa_yac) %>%
select(passer, test, everything())
```
The AQE methodology says that it uses the charting data from FTN.
```{r ftn_charting, include=TRUE}
ftn_charting <- nflreadr::load_ftn_charting(seasons = most_recent_season())
```
```{r ftn_charting_head, include=TRUE}
ftn_charting %>% head()
```