---
title: "NFL Punts Analytics Position and Velocity Diagrams Cohort 3 NGS 2016 7-12"
author: "Author: Roger Rosales (rosalesjrr@gmail.com)"
output:
  html_document:
    theme: cosmo
    toc: true
---

# Background
This kernel contains the Position and Velocity Diagrams for each punt concussion play in the NGS 2016 7-12.

My parent write up and analysis can be found in this kernel:

<a href="https://www.kaggle.com/predact/nfl-punts-analytics-wait-and-barrier">NFL Punts Analytics Wait and Barrier</a>

Please <strong>UPVOTE</strong> this kernel. I appreciate as I'm trying to get to Kaggle Expert. Thanks! 

Here are my other kernels for the other NFL punt plays with diagrams:

<a href="https://www.kaggle.com/predact/nfl-punts-pv-diagrams-ngs-2016-pre">-ngs-2016-pre</a>

<strong>Charts Explanation</strong>

The <em>Position Chart</em> shows the paths of the primary player (i.e. concussed player) and the primary_partner player (i.e. other player involved in the concussion collision).
We can see where they start the play and where they cross for the collision.
The chart is also showing where the punt was received or downed by the green box.
The gray box(es) indicate the position of each player when the punt was received or downed. 
The orange line shows where the plays starts.
Finally, you can see how fast the players are running by the gaps within their path. A larger gap means they are running faster.

The <em>Velocity Chart</em> shows the velocities of the primary player and the primary partner player.
We can see the velocities over the entire punt play. Velocity is measured in meters per second (m/s).
The chart also indicates when the ball was snapped to start the play, when the punt was received, and when the play ended via tackle, out of bounds, punt downed, fair catch touchback, etc.



```{r echo = FALSE, message=FALSE, warning=FALSE}
# Load in packages
##################################################################
#install.packages("data.table")
#install.packages("dplyr")
#install.packages("ggplot2")
#install.packages("stringr")
#install.packages("DT")
#install.packages("tidyr")
#install.packages("corrplot")
#install.packages("leaflet")
#install.packages("lubridate")



library(data.table)
library(dplyr)
library(ggplot2)
library(stringr)
library(DT)
library(tidyr)
library(corrplot)
library(leaflet)
library(lubridate)
###################################################################




# Load in the NFL Punt Analytics data
####################################################################
player.punt.data <- read.csv("../input/player_punt_data.csv")
player.role.data <- read.csv("../input/play_player_role_data.csv")
play.info <- read.csv("../input/play_information.csv")
game.data <- read.csv('../input/game_data.csv')
video.review <- read.csv('../input/video_review.csv')
video_footage_injury <- read.csv("../input/video_footage-injury.csv")
video_footage_control <- read.csv("../input/video_footage-control.csv")

#ngs <- read.csv("../input/NGS-2016-pre.csv")
#ngs <- read.csv("../input/NGS-2016-reg-wk1-6.csv")
ngs <- read.csv("../input/NGS-2016-reg-wk7-12.csv")
#ngs <- read.csv("../input/NGS-2016-reg-wk13-17.csv")

#For Kaggle Kernel
#player.punt.data <- read.csv("../input/player_punt_data.csv")
###################################################################






# Change classes for variables for analysis later on
###################################################################
ngs$GSISID <- as.factor(ngs$GSISID)
ngs$Time <- as.POSIXct(ngs$Time)
player.role.data$GSISID <- as.factor(player.role.data$GSISID)
#summary(ngs)
###################################################################






# Bring in Punt play information (only for manual input)
##################################################################

# gk = GameKey  
# pi = PlayId  
# gs1 = GSISID for primary player 
# gs2 = GSISID for partner player


# User input
#gk='5'
#pi='3129'
#gs1='31057'
#gs2='32482'
#pr='32482'
#pls='28284'
```

```{r echo=FALSE}
# Start of the function
puntstory <- function(gk,pi,gs1,gs2,pr,pls){


# Gather Data on the Primary and Partner players involved 
# Also manipulating the data for analysis
###################################################################


  
# Get primary player's punt role
Primary_Punt_Role <- player.role.data[player.role.data$GSISID==gs1&
                                        player.role.data$GameKey==gk&
                                        player.role.data$PlayID==pi,"Role"]

# Get primary player's activity derived
Primary_Activity <- video.review[video.review$GSISID==gs1&
                                   video.review$GameKey==gk&
                                   video.review$PlayID==pi,"Player_Activity_Derived"]

# Get primary player's impact type
Primary_Impact <- video.review[video.review$GSISID==gs1&
                                   video.review$GameKey==gk&
                                   video.review$PlayID==pi,"Primary_Impact_Type"]

# Get the flag if the concussion collision was friendly fire or not
Friendly_Fire <- video.review[video.review$GSISID==gs1&
                                 video.review$GameKey==gk&
                                 video.review$PlayID==pi,"Friendly_Fire"]


# Get partner player's punt role
Partner_Punt_Role <- player.role.data[player.role.data$GSISID==gs2&
                                        player.role.data$GameKey==gk&
                                        player.role.data$PlayID==pi,"Role"]

# Get partner player's activity derived
Partner_Activity <- video.review[video.review$GSISID==gs1&
                                   video.review$GameKey==gk&
                                   video.review$PlayID==pi,"Primary_Partner_Activity_Derived"]


# Filter the NGS data for the Primary Player and Sort by Time
primary.allplay <- ngs[ngs$GameKey == gk & ngs$PlayID == pi &
                         ngs$GSISID == gs1,]

primary.allplay <- primary.allplay[order(primary.allplay$Time),]



# Filter the NGS data for the Partner Player and Sort by Time
partner.allplay <- ngs[ngs$GameKey == gk & ngs$PlayID == pi &
                         ngs$GSISID == gs2,]

partner.allplay <- partner.allplay[order(partner.allplay$Time),]

# Filter the NGS data for the Punt Returner and Sort by Time
puntreturner.allplay <- ngs[ngs$GameKey == gk & ngs$PlayID == pi &
                         ngs$GSISID == pr,]

puntreturner.allplay <- puntreturner.allplay[order(puntreturner.allplay$Time),]

# Filter the NGS data for the PLS line of scrimmage and Sort by Time
pls.allplay <- ngs[ngs$GameKey == gk & ngs$PlayID == pi &
                              ngs$GSISID == pls,]

pls.allplay <- pls.allplay[order(pls.allplay$Time),]

# Keep track of important times during the punt
snap.time <- primary.allplay[primary.allplay$Event=="ball_snap","Time"]
punt.time <- primary.allplay[primary.allplay$Event=="punt","Time"]
punt_received.time <- primary.allplay[primary.allplay$Event=="punt_received","Time"]
fair_catch.time <- primary.allplay[primary.allplay$Event=="fair_catch","Time"]
touchback.time <- primary.allplay[primary.allplay$Event=="touchback","Time"]
oob.time <- primary.allplay[primary.allplay$Event=="out_of_bounds","Time"]
tackle.time <- primary.allplay[primary.allplay$Event=="tackle","Time"]
punt_downed.time <- primary.allplay[primary.allplay$Event=="punt_downed","Time"]

# Set the end of the punt play time by the maximum time of the ending events
end.time <-  max(punt_received.time,
                 fair_catch.time,
                 touchback.time,
                 oob.time,
                 tackle.time,
                 punt_downed.time)

#Punt location based on PLS position
pls.x <- pls.allplay[pls.allplay$Event=="ball_snap","x"]
pls.y <- pls.allplay[pls.allplay$Event=="ball_snap","y"]

#Punt Received Location
puntreturner.x <- puntreturner.allplay[puntreturner.allplay$Event=="punt_received","x"]
puntreturner.y <- puntreturner.allplay[puntreturner.allplay$Event=="punt_received","y"]

#Punt Downed Location
puntdowned.x <- puntreturner.allplay[puntreturner.allplay$Event=="punt_downed","x"]
puntdowned.y <- puntreturner.allplay[puntreturner.allplay$Event=="punt_downed","y"]

# Location of primary when punt received
primary.punt_received.x <- primary.allplay[primary.allplay$Event=="punt_received","x"]
primary.punt_received.y <- primary.allplay[primary.allplay$Event=="punt_received","y"]

# Location of partner when punt received
partner.punt_received.x <- partner.allplay[partner.allplay$Event=="punt_received","x"]
partner.punt_received.y <- partner.allplay[partner.allplay$Event=="punt_received","y"]


# Create a new data set from just the snap to the end of punt play time
primary.play <- as.data.frame(primary.allplay[primary.allplay$Time >= snap.time & primary.allplay$Time <= end.time,])

# Calculate the time since the play began
primary.play$playtime <- primary.play$Time - snap.time

table(primary.play$Event)

#str(primary.play$Event)

# OMIT: Calculate speed by MPH. Not very good because dist is not reliable.
# primary.play$mph <- primary.play$dis * (1/1760) / (0.1/3600)  

# Calculated Velocity for Primary by X and Y coordinates. Correct way
# Velocity = meters / sec  = Distance in meters / 1 second
primary.play$x_lag <- lag(primary.play$x, n = 10L) #10L to get one second change in time
primary.play$y_lag <- lag(primary.play$y, n = 10L)
primary.play$dist_meters <- 0.9144*sqrt((primary.play$x-primary.play$x_lag)^2 + (primary.play$y-primary.play$y_lag)^2)
primary.play$velocity <- primary.play$dist_meters / 1
primary.maxvelocity <- round(max(primary.play$velocity,na.rm = TRUE),digits=1)

# OMIT: Calculated MPH speed for Partner by dist column. Incorrect way.
# partner.play$mph <- partner.play$dis * (1/1760) / (0.1/3600)  

# Create partner play
partner.play <- as.data.frame(partner.allplay[partner.allplay$Time >= snap.time & partner.allplay$Time <= end.time,])

# Calculate the time since the play began
partner.play$playtime <- partner.play$Time - snap.time

# Calculated Velocity for Partner by X and Y coordinates
# 1 yard = 0.9144 meters
partner.play$x_lag <- lag(partner.play$x, n = 10L)
partner.play$y_lag <- lag(partner.play$y, n = 10L)
partner.play$dist_meters <- 0.9144*sqrt((partner.play$x-partner.play$x_lag)^2 + (partner.play$y-partner.play$y_lag)^2)
partner.play$velocity <- partner.play$dist_meters / 1
partner.maxvelocity <- round(max(partner.play$velocity,na.rm = TRUE),1)

# Primary Player Indicators
primary.play$Suffered.Concussion <- "Yes"
partner.play$Suffered.Concussion <- "No"




# Combine the primary play and the partner play
names(primary.play)
names(partner.play)
trueplay <- rbind(primary.play,partner.play)

trueplay[is.na(trueplay$velocity),"velocity"] <- 0



# Double arrow to use variables outside of the function
trueplay <<- trueplay
pls.x <<- pls.x
pls.y <<- pls.y
primary.punt_received.x <<- primary.punt_received.x
primary.punt_received.y <<- primary.punt_received.y
partner.punt_received.x <<- partner.punt_received.x
partner.punt_received.y <<- partner.punt_received.y
puntreturner.x <<- puntreturner.x
puntreturner.y <<- puntreturner.y
puntdowned.x <<- puntdowned.x
puntdowned.y <<- puntdowned.y
Primary_Punt_Role <<- Primary_Punt_Role
Primary_Activity <<- Primary_Activity
Primary_Impact <<- Primary_Impact
primary.maxvelocity <<- primary.maxvelocity
Partner_Punt_Role <<- Partner_Punt_Role
Partner_Activity <<- Partner_Activity
partner.maxvelocity <<- partner.maxvelocity
Friendly_Fire <<- Friendly_Fire
snap.time <<- snap.time
punt.time <<- punt.time
punt_received.time <<- punt_received.time
tackle.time <<- tackle.time
punt_downed.time <<- punt_downed.time
fair_catch.time <<- fair_catch.time
oob.time <<- oob.time
touchback.time <<- touchback.time

gk_gg <<- gk
pi_gg  <<- pi
gs1_gg <<- gs1
gs2_gg <<- gs2
pr_gg <<- pr
pls_gg <<- pls







} 
#end of function











# Run Plays

```

# Run Cohort 3 plays from the NGS 2016 7-12

## GameKey = 189, Play Id = 3509

```{r}
#####################################################################################
puntstory('189','3509','27595','31950','27595','30615')

################################################################
```

```{r echo=FALSE}
#Visualize the location of the primary and partner player during the concussion play.
print(h <- ggplot(data=trueplay, aes (x=x,y=y,color=Suffered.Concussion))+
  geom_point() + 
    
    geom_vline(aes(xintercept=pls.x),
               size=5,
               color="orange")+
    annotate("text",x=pls.x,y=pls.y+2,label="Play Start")+
    
    annotate("rect", xmin = primary.punt_received.x-3, xmax = primary.punt_received.x+3, ymin = primary.punt_received.y-3, ymax = primary.punt_received.y+3,
               alpha = .2)+
    annotate("rect", xmin = partner.punt_received.x-3, xmax = partner.punt_received.x+3, ymin = partner.punt_received.y-3, ymax = partner.punt_received.y+3,
             alpha = .2)+
    
    annotate("rect", xmin = puntreturner.x-3, xmax = puntreturner.x+3, ymin = puntreturner.y-3, ymax = puntreturner.y+3,
             alpha = .2, fill="green")+
    annotate("text",x=puntreturner.x,y=puntreturner.y,label="Punt Received")+
    
    annotate("rect", xmin = puntdowned.x-3, xmax = puntdowned.x+3, ymin = puntdowned.y-3, ymax = puntdowned.y+3,
             alpha = .2, fill="green")+
    annotate("text",x=puntdowned.x,y=puntdowned.y,label="Punt Downed")+
    
    labs(title="Zoomed Paths Traveled Leading to Concussion",
       subtitle=paste("GameKey =",gk_gg,"          PlayId=",pi_gg,
                      "\nConcussed Player:",Primary_Punt_Role,"--",Primary_Activity,Primary_Impact," -- Maximum Velocity= ",primary.maxvelocity," m/s",
                      "\nPartner Player:",Partner_Punt_Role,"--",Partner_Activity," -- Maximum Velocity= ",partner.maxvelocity," m/s",
                      "\nFriendly Fire? ",Friendly_Fire),
       caption = paste("+++The gray box indicates the player's location when the punt was received",
                      "\nSnap time: ",snap.time,
                      "\nPunt time: ",punt.time,
                      "\nPunt Received: ",punt_received.time,
                      "\nTackle time: ",tackle.time,
                      "\nPunt Downed time: ",punt_downed.time,
                      "\nFair Catch: ",fair_catch.time,
                      "\nOut of Bounds: ",oob.time,
                      "\nTouchback: ",touchback.time),
       x = "Yards along the Home Sideline",
       y = "Yards increasing up the Endzone"
       )
  )


# Visualize the velocity of the primary and partner player 
# in meters per second
print(g <- ggplot(data=trueplay, aes(x=Time, y = velocity, color=Suffered.Concussion)) + 
  geom_line(size=2)+ 
    geom_vline(aes(xintercept=punt.time),
               size=5,
               color="orange")+

    annotate("text",x=punt.time,y=4.25,label="Punt")+
    
    geom_vline(aes(xintercept=punt_received.time),
               size=5,
               color="green")+
    annotate("text",x=punt_received.time,y=4.25,label="Punt Received")+
    
    #annotate("pointrange", x = punt_downed.time, y = 4, ymin = 0, ymax = primary.maxvelocity,
    #         colour = "green", size = 0.5)+
    #annotate("text",x=punt_received.time,y=4.25,label="Punt Received")+
    #
    
    geom_vline(aes(xintercept=tackle.time),
               size=5,
               color="red")+
    annotate("text",x=tackle.time,y=4.25,label="Tackle")+
    
    #annotate("pointrange", x = oob.time, y = 4, ymin = 0, ymax = primary.maxvelocity,
    #         colour = "black", size = 0.5)+
    #annotate("text",x=oob.time,y=4.25,label="Out of Bounds")+
    
    
    labs(title="Velocity of Players leading to the Concussion Collision",
         subtitle=paste("GameKey =",gk_gg,"          PlayId=",pi_gg,
                        "\nConcussed Player:",Primary_Punt_Role,"--",Primary_Activity,Primary_Impact," -- Maximum Velocity= ",primary.maxvelocity," m/s",
                        "\nPartner Player:",Partner_Punt_Role,"--",Partner_Activity," -- Maximum Velocity= ",partner.maxvelocity," m/s",
                        "\nFriendly Fire? ",Friendly_Fire),
         caption = paste("\nSnap time: ",snap.time,
                         "\nPunt time: ",punt.time,
                         "\nPunt Received: ",punt_received.time,
                         "\nTackle time: ",tackle.time,
                         "\nPunt Downed time: ",punt_downed.time,
                         "\nFair Catch: ",fair_catch.time,
                         "\nOut of Bounds: ",oob.time,
                         "\nTouchback: ",touchback.time),
         x = "Time (seconds)",
         y = "Velocity (meters per second)"
         )
  )

```

* Punt Returner gets concussed after catching the ball and running it out.


<video width="800" height="600" controls> <source src="http://a.video.nfl.com//films/vodzilla/153242/Punt_by_Dustin_Colquitt-joFpAUDf-20181119_155010468_5000k.mp4" type="video/mp4"></video>




## GameKey = 231, Play Id = 1976

```{r}
#####################################################################################
puntstory('231','1976','32214','32807','24272','31156')

```

```{r echo=FALSE}

#Visualize the location of the primary and partner player during the concussion play.
print(h <- ggplot(data=trueplay, aes (x=x,y=y,color=Suffered.Concussion))+
  geom_point() + 
    
    geom_vline(aes(xintercept=pls.x),
               size=5,
               color="orange")+
    annotate("text",x=pls.x,y=pls.y+2,label="Play Start")+
    
    annotate("rect", xmin = primary.punt_received.x-3, xmax = primary.punt_received.x+3, ymin = primary.punt_received.y-3, ymax = primary.punt_received.y+3,
               alpha = .2)+
    annotate("rect", xmin = partner.punt_received.x-3, xmax = partner.punt_received.x+3, ymin = partner.punt_received.y-3, ymax = partner.punt_received.y+3,
             alpha = .2)+
    
    annotate("rect", xmin = puntreturner.x-3, xmax = puntreturner.x+3, ymin = puntreturner.y-3, ymax = puntreturner.y+3,
             alpha = .2, fill="green")+
    annotate("text",x=puntreturner.x,y=puntreturner.y,label="Punt Received")+
    
    annotate("rect", xmin = puntdowned.x-3, xmax = puntdowned.x+3, ymin = puntdowned.y-3, ymax = puntdowned.y+3,
             alpha = .2, fill="green")+
    annotate("text",x=puntdowned.x,y=puntdowned.y,label="Punt Downed")+
    
    labs(title="Zoomed Paths Traveled Leading to Concussion",
       subtitle=paste("GameKey =",gk_gg,"          PlayId=",pi_gg,
                      "\nConcussed Player:",Primary_Punt_Role,"--",Primary_Activity,Primary_Impact," -- Maximum Velocity= ",primary.maxvelocity," m/s",
                      "\nPartner Player:",Partner_Punt_Role,"--",Partner_Activity," -- Maximum Velocity= ",partner.maxvelocity," m/s",
                      "\nFriendly Fire? ",Friendly_Fire),
       caption = paste("+++The gray box indicates the player's location when the punt was received",
                      "\nSnap time: ",snap.time,
                      "\nPunt time: ",punt.time,
                      "\nPunt Received: ",punt_received.time,
                      "\nTackle time: ",tackle.time,
                      "\nPunt Downed time: ",punt_downed.time,
                      "\nFair Catch: ",fair_catch.time,
                      "\nOut of Bounds: ",oob.time,
                      "\nTouchback: ",touchback.time),
       x = "Yards along the Home Sideline",
       y = "Yards increasing up the Endzone"
       )
  )


# Visualize the velocity of the primary and partner player 
# in meters per second
print(g <- ggplot(data=trueplay, aes(x=Time, y = velocity, color=Suffered.Concussion)) + 
  geom_line(size=2)+ 
    geom_vline(aes(xintercept=punt.time),
               size=5,
               color="orange")+

    annotate("text",x=punt.time,y=4.25,label="Punt")+
    
    geom_vline(aes(xintercept=punt_received.time),
               size=5,
               color="green")+
    annotate("text",x=punt_received.time,y=4.25,label="Punt Received")+
    
    #annotate("pointrange", x = punt_downed.time, y = 4, ymin = 0, ymax = primary.maxvelocity,
    #         colour = "green", size = 0.5)+
    #annotate("text",x=punt_received.time,y=4.25,label="Punt Received")+
    #
    
    #geom_vline(aes(xintercept=tackle.time),size=5,color="red")+
    #annotate("text",x=tackle.time,y=4.25,label="Tackle")+
    
    annotate("pointrange", x = oob.time, y = 4, ymin = 0, ymax = primary.maxvelocity,colour = "black", size = 0.5)+
    annotate("text",x=oob.time,y=4.25,label="Out of Bounds")+
    
    
    labs(title="Velocity of Players leading to the Concussion Collision",
         subtitle=paste("GameKey =",gk_gg,"          PlayId=",pi_gg,
                        "\nConcussed Player:",Primary_Punt_Role,"--",Primary_Activity,Primary_Impact," -- Maximum Velocity= ",primary.maxvelocity," m/s",
                        "\nPartner Player:",Partner_Punt_Role,"--",Partner_Activity," -- Maximum Velocity= ",partner.maxvelocity," m/s",
                        "\nFriendly Fire? ",Friendly_Fire),
         caption = paste("\nSnap time: ",snap.time,
                         "\nPunt time: ",punt.time,
                         "\nPunt Received: ",punt_received.time,
                         "\nTackle time: ",tackle.time,
                         "\nPunt Downed time: ",punt_downed.time,
                         "\nFair Catch: ",fair_catch.time,
                         "\nOut of Bounds: ",oob.time,
                         "\nTouchback: ",touchback.time),
         x = "Time (seconds)",
         y = "Velocity (meters per second)"
         )
  )

```





* Three person collision at 0:12
* Receiving team blocker, blocks a Punting Team player into another Punting Team player. 
* Direction of Receiving Team blocker is opposite of Punt Returner
* Concussion happened after the punt was received


<video width="800" height="600" controls> <source src="https://nfl-vod.cdn.anvato.net/league/5691/18/11/25/284954/284954_75F12432BA90408C92660A696C1A12C8_181125_284954_huber_punt_3200.mp4"></video>





## GameKey = 234, Play Id = 3278

```{r}
#####################################################################################
puntstory('234','3278','28620','27860','27860','25503')


```

```{r echo=FALSE}

#Visualize the location of the primary and partner player during the concussion play.
print(h <- ggplot(data=trueplay, aes (x=x,y=y,color=Suffered.Concussion))+
  geom_point() + 
    
    geom_vline(aes(xintercept=pls.x),
               size=5,
               color="orange")+
    annotate("text",x=pls.x,y=pls.y+2,label="Play Start")+
    
    annotate("rect", xmin = primary.punt_received.x-3, xmax = primary.punt_received.x+3, ymin = primary.punt_received.y-3, ymax = primary.punt_received.y+3,
               alpha = .2)+
    annotate("rect", xmin = partner.punt_received.x-3, xmax = partner.punt_received.x+3, ymin = partner.punt_received.y-3, ymax = partner.punt_received.y+3,
             alpha = .2)+
    
    annotate("rect", xmin = puntreturner.x-3, xmax = puntreturner.x+3, ymin = puntreturner.y-3, ymax = puntreturner.y+3,
             alpha = .2, fill="green")+
    annotate("text",x=puntreturner.x,y=puntreturner.y,label="Punt Received")+
    
    annotate("rect", xmin = puntdowned.x-3, xmax = puntdowned.x+3, ymin = puntdowned.y-3, ymax = puntdowned.y+3,
             alpha = .2, fill="green")+
    annotate("text",x=puntdowned.x,y=puntdowned.y,label="Punt Downed")+
    
    labs(title="Zoomed Paths Traveled Leading to Concussion",
       subtitle=paste("GameKey =",gk_gg,"          PlayId=",pi_gg,
                      "\nConcussed Player:",Primary_Punt_Role,"--",Primary_Activity,Primary_Impact," -- Maximum Velocity= ",primary.maxvelocity," m/s",
                      "\nPartner Player:",Partner_Punt_Role,"--",Partner_Activity," -- Maximum Velocity= ",partner.maxvelocity," m/s",
                      "\nFriendly Fire? ",Friendly_Fire),
       caption = paste("+++The gray box indicates the player's location when the punt was received",
                      "\nSnap time: ",snap.time,
                      "\nPunt time: ",punt.time,
                      "\nPunt Received: ",punt_received.time,
                      "\nTackle time: ",tackle.time,
                      "\nPunt Downed time: ",punt_downed.time,
                      "\nFair Catch: ",fair_catch.time,
                      "\nOut of Bounds: ",oob.time,
                      "\nTouchback: ",touchback.time),
       x = "Yards along the Home Sideline",
       y = "Yards increasing up the Endzone"
       )
  )


# Visualize the velocity of the primary and partner player 
# in meters per second
print(g <- ggplot(data=trueplay, aes(x=Time, y = velocity, color=Suffered.Concussion)) + 
  geom_line(size=2)+ 
    geom_vline(aes(xintercept=punt.time),
               size=5,
               color="orange")+

    annotate("text",x=punt.time,y=4.25,label="Punt")+
    
    #geom_vline(aes(xintercept=punt_received.time),size=5,color="green")+
    #annotate("text",x=punt_received.time,y=4.25,label="Punt Received")+
    
    annotate("pointrange", x = punt_downed.time, y = 4, ymin = 0, ymax = primary.maxvelocity,colour = "green", size = 0.5)+
    annotate("text",x=punt_downed.time,y=4.25,label="Punt Received")+
    #
    
    #geom_vline(aes(xintercept=tackle.time),size=5,color="red")+
    #annotate("text",x=tackle.time,y=4.25,label="Tackle")+
    
    #annotate("pointrange", x = oob.time, y = 4, ymin = 0, ymax = primary.maxvelocity,colour = "black", size = 0.5)+
    #annotate("text",x=oob.time,y=4.25,label="Out of Bounds")+
    
    
    labs(title="Velocity of Players leading to the Concussion Collision",
         subtitle=paste("GameKey =",gk_gg,"          PlayId=",pi_gg,
                        "\nConcussed Player:",Primary_Punt_Role,"--",Primary_Activity,Primary_Impact," -- Maximum Velocity= ",primary.maxvelocity," m/s",
                        "\nPartner Player:",Partner_Punt_Role,"--",Partner_Activity," -- Maximum Velocity= ",partner.maxvelocity," m/s",
                        "\nFriendly Fire? ",Friendly_Fire),
         caption = paste("\nSnap time: ",snap.time,
                         "\nPunt time: ",punt.time,
                         "\nPunt Received: ",punt_received.time,
                         "\nTackle time: ",tackle.time,
                         "\nPunt Downed time: ",punt_downed.time,
                         "\nFair Catch: ",fair_catch.time,
                         "\nOut of Bounds: ",oob.time,
                         "\nTouchback: ",touchback.time),
         x = "Time (seconds)",
         y = "Velocity (meters per second)"
         )
  )
```

* Concussion collision happened at 0:10

* PRG on Punting Team #94 tackled PR by diving helmet first

* Concussion happened during run after punt was picked off the ground

<video width="800" height="600" controls> <source src="http://a.video.nfl.com//films/vodzilla/153244/Punt_by_Brad_Wing-5hmlbMBx-20181119_155243111_5000k.mp4"></video>