---
title: "NFL_punts"
author: "Will_Calhoun"
date: "December 16, 2018"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r, warning=FALSE, message=FALSE}
library(tidyverse)
library(dplyr)
library(ggplot2)
library(readr)
library(magrittr)
```
I am a recent graduate and have limited r programming knowledge, but just can'tseem to stop playing with it. I've 
encountered two issues, besides limited knowledge. First I am looking for a job during the holidays (which isn't too
promising) ans, second, I want to stay on top of what I've learned the past two semsters in R. I made a weak first attempt
and wasn't happy with the outcomes. Here's another stab at it.

Reading the data - Chunk2
```{r, warning=FALSE, message=FALSE}
pre2016 <- read_csv("../input/NGS-2016-pre.csv")
one2016 <- read_csv("../input/NGS-2016-reg-wk1-6.csv")
two2016 <- read_csv("../input/NGS-2016-reg-wk7-12.csv")
three2016 <- read_csv("../input/NGS-2016-reg-wk13-17.csv")
post2016 <- read_csv("../input/NGS-2016-post.csv")
```

Joining and filtering the 2016 data to include the concussion only plays - Chunk3
```{r, warning=FALSE, message=FALSE}
season2016a <- rbind(pre2016,one2016)
season2016b <- rbind(season2016a,two2016)
season2016c <- rbind(season2016b,three2016)
season2016 <- rbind(season2016c,post2016)
```

Chunk4
```{r, warning=FALSE, message=FALSE}
full2016season <-
    filter(season2016, GameKey == c(5,21,29,45,54,60,144,149,189,218,231,234,266,274,280,281,289,296) &
           PlayID == c(3129,2587,538,1212,1045,905,2342,3663,3509,3468,1976,3278,2902,3609,2918,3746,1526,2341,2667) &
           GSISID == c(31057,29343,31023,33121,32444,30786,32410,28128,27595,28987,32214,28620,23564,23742,32120,27654,28987,32007,32783))
```

Because of memory constraints, I was not able to repeat for the 2017 season in one kernal.
for this reason, analysis will now be done on the 2016 concussions by joining this to the video_review data.
Chunk5
```{r, warning=FALSE, message=FALSE}
video_review <- read_csv("../input/video_review.csv")
game_data <- read_csv("../input/game_data.csv")
punt_role <- read_csv("../input/play_player_role_data.csv")
```
Chunk6
```{r, warning=FALSE, message=FALSE}
games <- video_review %>% 
  left_join(game_data, by="GameKey")
```

Field Surface - Chunk7
```{r}
turf_type <- games %>%
  group_by(Turf) %>% 
  summarise(total_concuss = n(),prop=total_concuss/37)

  ggplot(turf_type, aes(x=Turf,y=total_concuss))+
  geom_col(fill="green")+
  labs(title="2016/2017 Punt Concussions", subtitle = "Grass-62% Turf-38%",
        x ="Turf Type", y = "Concussions")+
  coord_flip()+
  theme(legend.position="none")
```

Weather - Chunk8
```{r}
weather <- games %>%
  group_by(GameWeather) %>% 
  summarise(total_concuss = n(),prop=total_concuss/37)

  ggplot(weather, aes(x=GameWeather,y=total_concuss))+
  geom_col(fill="blue")+
  labs(title="2016/2017 Punt Concussions", subtitle = "Sunny-58%, Cloudy-42%",
        x ="Weather", y = "Concussions")+
  coord_flip()+
  theme(legend.position="none")
```

Friendly Fire - Chunk9
```{r}
video_review %>% group_by(Friendly_Fire) %>% 
  summarise(total_concuss = n(),prop=total_concuss/37) %>% 
  ggplot()+
  geom_col(aes(x=Friendly_Fire,y=total_concuss,fill="red"))+
  labs(title="2016/2017 Punt Concussions",
        x ="Due to Friendly Fire", y = "Concussions")+
  theme(legend.position="none")
```
Player Tracker: Tackling - Chunk10
```{r}
Player32444 <- pre2016 %>% 
  filter(GameKey==54,PlayID==1045,GSISID==32444)

Player32444 %>% 
ggplot(aes(x=x,y=y))+
  geom_line()+
  scale_y_continuous(limits = c(0,53.3))+
  labs(title="2016 Preseason", subtitle = "Steelers at Panthers",
        x ="Sideline", y = "Endzone")
```

Player Tracker: Blocked - Chunk11
```{r}
Player32444 <- pre2016 %>% 
  filter(GameKey==54,PlayID==1045,GSISID==32444)

Player32444 %>% 
ggplot(aes(x=x,y=y))+
  geom_line()+
  scale_y_continuous(limits = c(0,53.3))+
  labs(title="2016 Preseason", subtitle = "Steelers at Panthers",
        x ="Sideline", y = "Endzone")
```






