knitr::opts_chunk$set(echo = TRUE)

Introduction

My final presentation is the focused on Offensive Lineman and what in their control. Lineman do not make the passes and catches but they give the quaterback the time to do so. Yet factors that interfer with how well they do their job is based on how many defenders are in the box and the offensive personnel theyโ€™re in.

suppressWarnings(suppressMessages(library(data.table)))
suppressWarnings(suppressMessages(library(dplyr)))
suppressWarnings(suppressMessages(library(ggplot2)))
suppressWarnings(suppressMessages(library(gganimate)))
suppressWarnings(suppressMessages(library(gifski)))
suppressWarnings(suppressMessages(library(httr)))
suppressWarnings(suppressMessages(library(lubridate)))
suppressWarnings(suppressMessages(library(ggalt)))

setwd("U:/")

# Files Needed
pffScouting <- fread("pffScoutingData.csv")
plays <- fread("plays.csv")
players <- fread("players.csv")

#All plays with Eleven Personnel and Play Action
elevenPersonnelPlaysPA<- plays%>%
  select(passResult,personnelO,defendersInBox,pff_playAction)%>%
  filter(passResult %in% c('C','I','S'), personnelO == '1 RB, 1 TE, 3 WR')%>%
  mutate(ifelse(passResult=='C',1,0),
         ifelse(passResult=='I',1,0),
         ifelse(passResult=='S',1,0))%>%
  filter(pff_playAction == 1)%>%
  data.frame()



#All plays with Eleven Personnel and No Play Action
elevenPersonnelPlays<- plays%>%
  select(passResult,personnelO,defendersInBox,pff_playAction)%>%
  filter(passResult %in% c('C','I','S'), personnelO == '1 RB, 1 TE, 3 WR')%>%
  mutate(ifelse(passResult=='C',1,0),
        ifelse(passResult=='I',1,0),
        ifelse(passResult=='S',1,0))%>%
  filter(pff_playAction == 0)%>%
  data.frame()

#Sorting for the necessary Pass Block Data
passBlockData <- pffScouting%>%
select(nflId,pff_role,pff_blockType,pff_hitAllowed,pff_beatenByDefender,pff_hurryAllowed,pff_sackAllowed)%>%
  filter(pff_role == 'Pass Block', pff_blockType %in% c('PP','PA'))%>%
  mutate(ifelse(pff_beatenByDefender==1,1,0),
         ifelse(pff_hurryAllowed==1,1,0),
         ifelse(pff_hitAllowed==1,1,0),
         ifelse(pff_sackAllowed==1,1,0))%>%
  data.frame()

#Sort Data to only focus on the Tackle Position 'T'
positionTackle <- players%>%
  select(nflId,officialPosition,displayName)%>%
  filter(officialPosition %in% c('T'))%>%
  data.frame()


#Terron Armstead #72
player72 <- positionTackle %>%
  select(displayName,nflId)%>%
  filter(displayName == 'Terron Armstead')%>%
  data.frame()

Rating Formula

I have created a formula based on different variables such as defenders in the box and the amount of potiental help which is the other people besides lineman that can block.

#Merging Data to Explore Terron Armstead
playerDataPA <- merge(elevenPersonnelPlaysPA,player72)
playerPlayActionRole <- merge(playerDataPA,passBlockData,by.x = c('nflId'),all.x = TRUE)

#Player is in Standard Pass Protection 
playerIsPP <- playerPlayActionRole%>%
  select(passResult,defendersInBox,pff_blockType,pff_hitAllowed,pff_beatenByDefender,
         pff_hurryAllowed,pff_sackAllowed)%>%
  filter(pff_blockType == 'PP')%>%
  filter(pff_hitAllowed ==1 | pff_hurryAllowed ==1 |pff_beatenByDefender ==1 | pff_sackAllowed ==1)%>%
  data.frame()

ratingFormula <- playerIsPP%>%
  select(passResult,defendersInBox,pff_hitAllowed,pff_beatenByDefender,
         pff_hurryAllowed,pff_sackAllowed)%>%
  group_by(passResult,defendersInBox)%>%
  filter(defendersInBox == 5,defendersInBox==6,defendersInBox==7)%>%
  mutate(Hit=sum(pff_hitAllowed),Hurry=sum(pff_hurryAllowed),Beaten=sum(pff_beatenByDefender),
            Sack=sum(pff_sackAllowed))%>%
  data.frame()

ratingFormula <- ratingFormula %>%
  mutate(Hit==sum(pff_hitAllowed),Hurry==sum(pff_hurryAllowed),Beaten==sum(pff_beatenByDefender),
            Sack==sum(pff_sackAllowed),.groups = 'keep')%>%
  mutate(leftSide= (5+(2/2)-(defendersInBox)))%>%
  mutate(totalPasses = Hit+Hurry+Beaten+Sack)%>%
data.frame()



CompletePassResults <- ratingFormula%>%
  group_by(passResult,defendersInBox)%>%
  #complete -Beaten
  mutate(CPRBeaten = leftSide+(1*1))%>%
  mutate(totalRatingBeaten = CPRBeaten * Beaten)%>%
  #complete - Hit 
  mutate(CPRHit = leftSide+(1*2))%>%
  mutate(totalRatingHit = CPRHit * Hit)%>%
  
  #complete - Hurry 
  mutate(CPRHurry = leftSide+(1*3))%>%
  mutate(totalRatingHurry= CPRHurry * Hurry)%>%
  
  #complete - Sack
  mutate(CPRSack = leftSide+(1*4))%>%
  mutate(totalRatingSack = CPRSack * Sack)%>%
  data.frame()



IncompletePassResults<- ratingFormula%>%
  group_by(passResult,defendersInBox)%>%
  #Incomplete -Beaten
  mutate(IPRBeaten = leftSide+(2*1))%>%
  mutate(totalRatingBeaten = IPRBeaten * Beaten)%>%
  #Incomplete - Hit 
  mutate(IPRHit = leftSide+(2*2))%>%
  mutate(totalRatingHit = IPRHit * Hit)%>%
  
  #Incomplete - Hurry 
  mutate(IPRHurry = leftSide+(2*3))%>%
  mutate(totalRatingHurry= IPRHurry * Hurry)%>%
  
  #Incomplete - Sack
  mutate(IPRSack = leftSide+(2*4))%>%
  mutate(totalRatingSack = IPRSack * Sack)%>%
  data.frame()



SackedPassResults <- ratingFormula%>%
  group_by(passResult,defendersInBox)%>%
  #Sacked -Beaten
  mutate(SPRBeaten = leftSide+(3*1))%>%
  mutate(totalRatingBeaten = SPRBeaten * Beaten)%>%
  #Sacked- Hit 
  mutate(SPRHit = leftSide+(3*2))%>%
  mutate(totalRatingHit = SPRHit * Hit)%>%
  
  #Sacked - Hurry 
  mutate(SPRHurry = leftSide+(2*3))%>%
  mutate(totalRatingHurry= SPRHurry * Hurry)%>%
  
  #Sacked - Sack
  mutate(SPRSack = leftSide+(2*4))%>%
  mutate(totalRatingSack = SPRSack * Sack)%>%
  data.frame()