{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"markdown","source":" # NFL Punt Analytics Data Exploration Part 2 \n\nHello all. Welcome to part 2 of my exploration of the NFL Punt Analytics Competition data. In my previous NFL kernel, I had extracted the relevant data of plays where concussions had occurred and also looked into a few other  areas of the data. We hadn't yet uncovered anything particularly useful then :( Hopefully, this kernel will lead us to some \"gold\" :D\n\nHere's the link or the previous kernel: https://www.kaggle.com/tmunyanyi22/starting-the-nfl-punt-analytics-comp\n\n\nIn this kernel , we will look at the position of players, special team types , player activity during plays , speed,and player impact type , and try to see if there's a link between any of these areas and whether or not a player receives a concussion.\n\nLet's begin !\n"},{"metadata":{"_uuid":"a19073209a6486c8caf60862bc8f9312c172382b"},"cell_type":"markdown","source":"**Loading in required data and packages**"},{"metadata":{"trusted":true,"_uuid":"e5528669c51867ff369a489e4aec23b8e33342c6"},"cell_type":"code","source":"#Loading in useful packages for data manipulation\nlibrary(\"tidyverse\")\nlibrary(\"stringr\")\nlibrary(\"gridExtra\")\nlibrary(\"dplyr\")\nlibrary(\"lubridate\")\nlibrary(\"utils\")\nlibrary(\"PopED\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"acb9060e193defa3be24b36286dd025e10513f78"},"cell_type":"markdown","source":"I'll load in some R data from the previous kernel I was worked on. This has all of the NGS data for the primary players,-it's under the name 'NGS_total_injure'-and the player partner data is included too - under the name ' PP_NGS_total_injure'."},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"#Load useful R data\nload(\"../input/nfl-data/NFL_DATA.RData\")\nload(\"../input/play-part/Play_Part.RData\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9d9c81663ae93141637e0114a735f30c39089a04"},"cell_type":"code","source":"#load in the play information\nplay_info = read.csv('../input/NFL-Punt-Analytics-Competition/play_information.csv')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"0b2d11ace71fa123018c279e699d637f432a8a2a"},"cell_type":"markdown","source":"# **Player Activity**\n\nLet's start by examining the player activity and partner's activity variables for players who received concussions. We will do this using bar charts!\n"},{"metadata":{"trusted":true,"_uuid":"018a7206459d74023ad97b696a35a66e2a6eed2a"},"cell_type":"code","source":"#By player activity\nvideo_review %>%\n  ggplot(mapping=aes(x=Player_Activity_Derived,y =(..count..)/sum(..count..))) +\n  geom_bar() +\n  geom_text(aes(label= round(100*(..count..)/sum(..count..),2)),stat='count' ,position=position_dodge(width=0.9), vjust=-0.75) +\n  xlab(\"Activity\") +\n  ylab(\"Percent\") +\n  scale_y_continuous(labels = scales::percent) +\n  ggtitle(\"What was the player doing prior to receiving the concussion ?\")\n\n#By player partner activity\nvideo_review %>%\n  ggplot(mapping=aes(x=Primary_Partner_Activity_Derived,y = (..count..)/sum(..count..))) + \n  geom_text(aes(label= round(100*(..count..)/sum(..count..),2)),stat='count' ,position=position_dodge(width=0.9), vjust=-0.75) +\n  geom_bar() + \n  xlab(\"Partner Activity\") + \n  ylab(\"Percent\") +\n  scale_y_continuous(labels = scales::percent) +\n  ggtitle(\"What was the player's partner doing prior to the player receiving the concussion?\")\n","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"4eeacd1de78e571f6425726f0990046e9d87906c"},"cell_type":"markdown","source":"It appears that for players who received a concussion, **over 60% of them  were being blocked or were tackling another player**. This is interesting and potentially useful, I'll keep that in mind going forward.\n\nLooking at player partner activity, **just over 54% of player partners were tackling or being blocked**. Not quite what I expected - I thought the numbers for 'Tackled' and 'Blocking' would go up here, we'll have to look into why this is happening later on.\n\nLet's examine player roles and special team types..."},{"metadata":{"_uuid":"f8d462f6c1e49537c1542cd5a11dd3eec4a830f2"},"cell_type":"markdown","source":"\n# **Player roles and special team types**\n\n\n\n**!DEFINITION ALERT!**\n\n*What is a special team ? *\n\n**According to wikipedia , special teams are units on the field during the kicking plays. Coverage and Return are two special teams in punt plays.**\n\n\nRight, now that we've got the definitions out of the way, let's see how player roles and special team types are distributed for players who received concussions."},{"metadata":{"_uuid":"b12e4f80642edd651ad8e59c1a73dd5abb5d5f7f"},"cell_type":"markdown","source":"Our video review data, unfortunately, does not have the player roles and special team types data. We'll have to add it in. Luckily, all this detail about roles and positions is avaliable in the play_player_role_data.csv file."},{"metadata":{"trusted":true,"_uuid":"1a318a66c1984e11575ac448ad345c14beff53d9"},"cell_type":"code","source":"#Now to add roles and positions to the video review table\nat_risk_role = tibble ()\nfor (i in 1:37) {\nat_risk_role<- rbind(at_risk_role,play_player_role_data %>%\n  select(Role) %>%\n  filter(play_player_role_data$GameKey == video_review$GameKey[i],play_player_role_data$PlayID ==video_review$PlayID[i],play_player_role_data$GSISID ==video_review$GSISID[i]))\n}\n\nvideo_review$Role <- as.factor(as.matrix(at_risk_role))\n\n#Now to add positions to the video review table\nat_risk_pos = tibble()\nfor (i in 1:37) {\n  at_risk_pos<- rbind(at_risk_pos,unique(player_punt_data[,c(1,3)]) %>%\n                        select(Position) %>%\n                        filter(unique(player_punt_data[,c(1,3)])$GSISID ==video_review$GSISID[i]))\n}\nvideo_review$Position <- as.factor(as.matrix(at_risk_pos))\n","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8e92c80fc8e498ec7f0bf1ae0223046b8c07c1a4"},"cell_type":"markdown","source":"To add in the special team type, we'll have to get a bit crafty because it is not included explicity in the data.\nThe play_player_role_data.csv does,however, contain roles and using these we can assign a player as part of either the coverage team or return team. Details of which roles belong to which team are avaliable on the competitions page.\n\nLet's add in a speical teams column, specifying which special team a player is part of: Coverage or Return...."},{"metadata":{"trusted":true,"_uuid":"7d6b8f881d391f33f472b47858947a30d56ffd56"},"cell_type":"code","source":"#Let's make vector of roles in the coverage team\npunt_coverage  = c(\"P\",\"PPL\",\"PPLi\",\"PPLo\",\"PPR\",\"PPRi\",\"PPRo\",\"PC\",\"PLW\",\"PRW\",\"PLT\",\"PRT\",\"PLG\",\"PLS\",\"PRG\",\"GL\",\"GLi\",\"GLo\",\"GR\",\"GRi\",\"GRo\")\npunt_return =  c(\"PR\",\"PFB\",\"PLL\",\"PLL1\",\"PLL2\",\"PLL3\",\"PLM\",\"PLM1\",\"PLR\",\"PLR1\",\"PLR2\",\"PLR3\",\"PDL1\",\"PDL2\",\"PDL3\",\"PDL4\",\"PDL5\",\"PDL6\",\"PDM\",\"PDR1\",\"PDR2\",\"PDR3\",\"PDR4\",\"PDR5\",\"PDR6\",\"VR\",\"VRi\",\"VRo\",\"VL\",\"VLi\",\"VLo\")\n\n#Let's a add new column our table : coverage or return\nvideo_review$Special_team <- ifelse(video_review$Role %in% punt_coverage,\"Coverage\",\"Return\")\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6c9fa8feece2e02cfc2508f6cb897bbf37854a8d"},"cell_type":"code","source":"#Let's make the plot\nvideo_review %>%\n  ggplot(mapping=aes(x=Role,y = (..count..)/sum(..count..))) + \n  geom_bar() + \n  xlab(\"Role\") + \n  scale_y_continuous(labels = scales::percent) +\n  ylab(\"Percent\") +\n  ggtitle(\"Which Punt Play Roles experienced concussions?\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"fd9ee77c925081a8c4b94e11cd5c8408aaab505f"},"cell_type":"markdown","source":"This graph is clearly showing us that there's a few special team roles  that have a lot more concussions than others. There are many of them in fact and so we'll break it down further to make it easier to take in....."},{"metadata":{"trusted":true,"_uuid":"94d3d801c41520bbca4f4b22a632b0cf9e8931bb"},"cell_type":"code","source":"#Let's make plot to see whether concussion players are part of Coverage or Return\nvideo_review %>%\n  ggplot(mapping=aes(x=Special_team,y = (..count..)/sum(..count..))) + \n  geom_text(aes(label= round(100*(..count..)/sum(..count..),2)),stat='count' ,position=position_dodge(width=0.9), vjust=-0.25) +\n  geom_bar() + \n  xlab(\"Special Team\") + \n  ylab(\"Percent\") +\n  scale_y_continuous(labels = scales::percent) +\n  ggtitle(\"Are concussion players from the coverage team or from the return team ?\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"55688025bfafae2537dfd4c5ccd1d0b7219497a0"},"cell_type":"markdown","source":"Okay, it looks like **over 70% of the concussion players are part of the Coverage special team**. Let's see which roles these players occupy in the coverage teams"},{"metadata":{"trusted":true,"_uuid":"182d2d9aa7becfa105f82a82ad82090c46e0939a"},"cell_type":"code","source":"#Let's see which position in the coverage team is most susceptible to concussions ?\nvideo_review %>%\n  select(Role) %>%\n  filter(Role %in% punt_coverage) %>%\n  arrange(desc(Role)) %>%\n  ggplot(mapping=aes(x=Role,y = (..count..)/sum(..count..))) + \n  geom_bar() + \n  xlab(\"Role\") +  \n  ylab(\"Percent\") +\n  scale_y_continuous(labels = scales::percent) +\n  geom_text(aes(label= round(100*(..count..)/sum(..count..),2)),stat='count' ,position=position_dodge(width=0.9), vjust=-0.75) +\n  ggtitle(\"Which role in the coverage team is most vulnerable to concussions ?\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"9d0ecca3338798e4e5767b688805be8c9672af35"},"cell_type":"markdown","source":"This graph is telling us that **the PLG,PLW, PRG and GL have high frequencies of concussions among concussion players compared to other roles in the Coverage special team.**\n\nLet's also take a look at a break down of the Return special team..."},{"metadata":{"trusted":true,"_uuid":"b7d0aff4f7d61069129365ec76a7bee99853edf0"},"cell_type":"code","source":"#Let's see which position in the return team is most susceptible to concussions\nvideo_review %>%\n  select(Role) %>%\n  filter(Role %in% punt_return) %>%\n  ggplot(mapping=aes(x=Role,y = (..count..)/sum(..count..))) + \n  geom_bar() + \n  xlab(\"Role\") + \n  ylab(\"Percent\") +\n  scale_y_continuous(labels = scales::percent) +\n   geom_text(aes(label= round(100*(..count..)/sum(..count..),2)),stat='count' ,position=position_dodge(width=0.9), vjust=-0.75) +\n  ggtitle(\"Which role in the return team is most vulnerable to concussions ?\")\n\n","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"4ef319049aa67a146fa3152a71f68c03d7bc9baa"},"cell_type":"markdown","source":"It's clear that among the concussions that occurred in Return team, **the PR role had a significantly higher frequency than all the other Return team roles**. \n\nIn addition to this, let's consider what each player was doing"},{"metadata":{"trusted":true,"_uuid":"ea361d39f64192aaaa82da290c4334ded8547aa6"},"cell_type":"code","source":"#Let's see which position in the coverage team is most susceptible to concussions ?\nvideo_review %>%\n  select(Role,Player_Activity_Derived) %>%\n  filter(Role %in% punt_coverage) %>%\n  arrange(desc(Role)) %>%\n  ggplot(mapping=aes(x=Role,fill=factor(Player_Activity_Derived),y = (..count..)/sum(..count..))) + \n  geom_bar() + \n  xlab(\"Role\") + \n  ylab(\"Percent\") +\n  scale_y_continuous(labels = scales::percent) +\n  labs(fill=\"Player Activity\") +\n  ggtitle(\"Which role in the coverage team is most vulnerable to concussions ?\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"2a6495152875a9064165e272df3ea46f48a659a4"},"cell_type":"markdown","source":"This graph is telling us that among concussion players who part of the coverage team, **an overwhelming majority were tackling or were blocked when they received the concussion**. This isn't surprising given of the way in which the coverage team aggressively works on trying to get down field and stop the return from returning."},{"metadata":{"trusted":true,"_uuid":"7aae967e12c782d021510621805192e1bbc399ae"},"cell_type":"code","source":"#Let's see which position in the return team is most susceptible to concussions\nvideo_review %>%\n  select(Role,Player_Activity_Derived) %>%\n  filter(Role %in% punt_return) %>%\n  ggplot(mapping=aes(x=Role,fill=factor(Player_Activity_Derived),y = (..count..)/sum(..count..))) + \n  geom_bar() + \n  xlab(\"Role\") +\n  ylab(\"Percent\") +\n  labs(fill=\"Player Activity\") +\n  scale_y_continuous(labels = scales::percent) +\n  ggtitle(\"Which role in the return team is most vulnerable to concussions ?\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"2e56e6044310bc07018b6a862173ae19e805ef9a"},"cell_type":"markdown","source":"This graph is telling us that among concussion players who part of the return team, **there was an equal split in terms of receiving the concussion when being tackled or blocking**."},{"metadata":{"_uuid":"a1ffd903f80019cd7c8490d85ec44e94e7f12e30"},"cell_type":"markdown","source":"# **Player speed**\n\nAlright, so far we've realised that among the video review data, significantly more coverage team players are receiving concussions than return team players. We are now going to examine the speed differential between coverage players and return players. \n\nTo do this, I'd normally use the totality of the NGS data and split it into concussion and non-concussion,but because my computer is limited , I'm going to use the video review data to get a simple and rough picture of how great the speed differential , instead. \n\nFirst, let's add a column with maximum speeds to our Video Review data..."},{"metadata":{"trusted":true,"_uuid":"21d76d67c5d872e32f60e22ba3c0465c0966a9a1"},"cell_type":"code","source":"#First, let's change the distance moved from yards to miles\ndis_in_miles <- NGS_total_injure$dis / 1760\ndis_in_miles <- dis_in_miles\n\n#Now, I know that the time between each observation is roughly 0.1 , so I'll divide my vector of distance by 0.1 to get the speed and multiply by 1.61 to get kph\nspeeds = 60*60*dis_in_miles/0.1 \n\n#I'll create a new speed column in the NGS_total_injure table\nNGS_total_injure$speeds = round(speeds, digits = 3)\n\n\n#Next,i'll want to see the max speeds for concussion players during plays\nmax_speeds = c()\nfor (i in 1:37){\n  a = NGS_total_injure %>%\n    select(speeds) %>%\n    filter(NGS_total_injure$GameKey == video_review$GameKey[i],NGS_total_injure$PlayID==video_review$PlayID[i],NGS_total_injure$GSISID == video_review$GSISID[i])%>%\n    arrange(desc(speeds))\n  max_speeds = rbind(max_speeds,mean(as.matrix(a)[c(10,30,70,90)]))\n}\n\n#Add this max speeds column to the ting\nvideo_review$Max_speeds = max_speeds","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"558fa62efa80a2edd632dcb3f7b62446d99fbc3d"},"cell_type":"markdown","source":"Alright let's make a plot of the distribution of speeds in total for all players in the Video Review data, and then we'll make another graph show the speeds of coverage and return players in the Video Review data."},{"metadata":{"trusted":true,"_uuid":"1ed2d21238a16a352aad816da921449850066ba8"},"cell_type":"code","source":"##Let's make a graph of all the speeds\nvideo_review %>%\n  ggplot(mapping=aes(x=as.vector(Max_speeds))) + \n  geom_density() +\n  geom_vline(xintercept = 23.24,linetype=\"dotted\",color='blue')+\n  xlab(\"Max speeds(mph)\") +\n  ggtitle(\"What's the max speed for concussion players ?\")\n\n#Let's make a graph of the speed according to special teams \nvideo_review %>%\n  ggplot(mapping=aes(x=as.vector(Max_speeds),color=factor(Special_team))) + \n  geom_density()+\n  labs(color=\"Special Team\") +\n  geom_vline(xintercept = 23.24,linetype=\"dotted\",color='blue')+\n  xlab(\"Max speeds(mph)\") +\n  scale_y_continuous(labels = scales::percent) +\n  ggtitle(\"What's the max speed for concussion coverage players versus concussion return players ?\")\n\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fae3e25c5440010de05096c7525e85eeb64df14c"},"cell_type":"code","source":"#What is the average max speed in total\npaste('Average speed for both Coverage and Return teams: ',round(mean(video_review$Max_speeds),2),\"mph\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b19734114caa7b32e3e5aa1f91fd6070d26ef970"},"cell_type":"code","source":"#What is the average max speed for coverage players\nx <-  as.matrix(video_review %>%\n    select(Max_speeds) %>%\n    filter(video_review$Special_team == \"Coverage\"))\n\npaste('Average speed for Coverage team: ',round(mean(as.numeric(x)),2),\"mph\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"33adb3925ddd828f4fb9aa278375c813ef5f0121"},"cell_type":"code","source":"#What is the average max speed for return players ?\nx <-  as.matrix(video_review %>%\n    select(Max_speeds) %>%\n    filter(video_review$Special_team == \"Return\"))\n\npaste('Average speed for Return team: ',round(mean(as.numeric(x)),2),\"mph\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"07e7aaec8f7151653bb700364eed5cdc5a4afb5b"},"cell_type":"markdown","source":"Intrepeting this graph requires us to have watched some of the clips in in the video review player footage file and also gotten a grasp of how punt plays work.\n\nThe graph shows the Return team player max speeds having a greater range were the density is greater than zero. The reason for this is that Return teams are composed of different sections - one section waits for the ball to be kicked to them and the other is trying to get to the punter before he kicks it. The result is players with different max speeds.\n\nThe graph shows the Coverage team max speeds having density for maximum speed at roughly 12.50mph. The reason for this is that once the punter has kicked the ball, everyone from the coverage team sprints full tilt down the field to stop the returning team from bring the ball back too.\n\nKey takeaways from this graph are:\n\n**Coverage players hit roughly their maximum speeds more oftern than return players**\n\n**Return players don't hit their maximum speeds nearly as much**\n\nFor the rest of this kernel , I'll consider any  speeds at 13mph and over as running flatout. This is because the fastest average max speed at receiver for a team is 13.33mph, according to the New York Times. Link : https://www.nytimes.com/2018/01/04/sports/football/nfl-speed-leonard-fournette.html\n\nLet's do a further speed analysis , but first we have to add a speed column for the primary partner....\n\n"},{"metadata":{"trusted":true,"_uuid":"beef1d5f3d0ec3efa922aa3990e93f8a42004624"},"cell_type":"code","source":"#First, let's change the distance moved from yards to miles\npdis_in_miles <- PP_NGS_total_injure$dis / 1760\npdis_in_miles <- pdis_in_miles\n\n#Now, I know that the time between each observation is roughly 0.1 , so I'll divide my vector of distance by 0.1 to get the speed and multiply by 1.61 to get kph\npspeeds = 60*60*pdis_in_miles/0.1 \n\n#I'll create a new speed column in the NGS_total_injure table\nPP_NGS_total_injure$speeds = round(pspeeds, digits = 3)\n\n\n#Next,i'll want to see the max speeds for concussion players during plays\npmax_speeds = c()\nfor (i in 1:37){\n    z = PP_NGS_total_injure %>%\n    select(speeds) %>%\n    filter(PP_NGS_total_injure$GameKey == video_review$GameKey[i],PP_NGS_total_injure$PlayID==video_review$PlayID[i],PP_NGS_total_injure$GSISID == video_review$Primary_Partner_GSISID[i])%>%\n    arrange(desc(speeds))\n    pmax_speeds = rbind(pmax_speeds,mean(as.matrix(z)[c(10,30,70,90)]))\n}\n\n#Add this max speeds column to the ting\nvideo_review$Partner_Max_speeds = pmax_speeds","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"a66571921b808a3ef98f9ddd54f5281bf4767143"},"cell_type":"markdown","source":"# **Player Impact Type**\n\nLet's examine the player impact types alongside player activity, player roles in coverage and return teams......."},{"metadata":{"trusted":true,"_uuid":"aa74f902a67c17de3013cbd90a77782cbcecb343"},"cell_type":"code","source":"video_review %>%\n    select(Primary_Impact_Type,Player_Activity_Derived) %>%\n    ggplot(mapping=aes(x=Player_Activity_Derived,fill=Primary_Impact_Type,y = (..count..)/sum(..count..))) +\n    labs(fill=\"Primary Impact Type\") +\n    xlab(\"Player Activity\") +\n    geom_bar() +\n    ylab(\"Percent\") +\n    scale_y_continuous(labels = scales::percent) +\n    ggtitle(\"During a concussion player's activity, what type of collision did they have ?\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"a7114fd750d8e3b1747ac7f3fdee66a8288be180"},"cell_type":"markdown","source":"This graph is telling us that injuries occuring from helmet-to-helemet contact is reasonably constant across all player activity: 13.51, 10.81, 10.81, 10.81\n\nHelmet-to-body fluctuates a lot more: 8.11, 10.81, 5.41, 21.62\n\nHelmet-to-ground and Unclear seem inconsequential.\n\nIt therefore seems that helmt-to-helmet contact is a systematic part of the punt play, regardless of what the player is doing.\n\nHelmet-to-body contant,however, seems like it could be like's very dependent on the player DOING AN ACT, either blocking or tackling, rather than receiving the act. This is important because helment-to-body contact makes 46% percent of all concussion player contact."},{"metadata":{"trusted":true,"_uuid":"a2c1a16ef38f02fba9c91cbc805a7f0dd8e2ea2c"},"cell_type":"code","source":"#Assiging bins to player speed\nvideo_review$player_speedbins <- ifelse(video_review$Max_speeds > 25,'25+ mph',ifelse(video_review$Max_speeds > 20,'20-25 mph',ifelse(video_review$Max_speeds > 15,'15-20 mph',ifelse(video_review$Max_speeds > 10,'10-15 mph',ifelse(video_review$Max_speeds > 5,'5-10mph','0-5mph')))))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e1f8539367f9bfef1ad776c4dea3d8da4a5ac555"},"cell_type":"code","source":"video_review %>%\n    select(Primary_Impact_Type,player_speedbins) %>%\n    ggplot(mapping=aes(x=as.vector(Primary_Impact_Type),fill=as.vector(player_speedbins),y = (..count..)/sum(..count..))) +\n    labs(fill=\"Player Speed\") +\n    xlab(\"Player Activity\") +\n    geom_bar() +\n    ylab(\"Percent\") +\n    scale_y_continuous(labels = scales::percent) +\n    ggtitle(\"When a concussion player made impact, what speed were they moving at ?\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"32da47ba5490b0d384098a1664ad29041afef820"},"cell_type":"code","source":"video_review %>%\n    select(Player_Activity_Derived,player_speedbins) %>%\n    ggplot(mapping=aes(x=as.vector(Player_Activity_Derived),fill=as.vector(player_speedbins),y = (..count..)/sum(..count..))) +\n    labs(fill=\"Player Speed\") +\n    xlab(\"Player Activity\") +\n    geom_bar() +\n    ylab(\"Percent\") +\n    scale_y_continuous(labels = scales::percent) +\n    ggtitle(\"When the concussion player was activity, what speed were they moving at ?\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1f1af1e65e8ccab191819e01076d6d0069a577d7"},"cell_type":"code","source":"video_review %>%\n  select(Role,player_speedbins) %>%\n  filter(Role %in% punt_coverage) %>%\n  arrange(desc(Role)) %>%\n  ggplot(mapping=aes(x=Role,fill=factor(player_speedbins),y = (..count..)/sum(..count..))) + \n  geom_bar() + \n  xlab(\"Coverage Role\") + \n  ylab(\"Percent\") +\n  scale_y_continuous(labels = scales::percent) +\n  labs(fill=\"Player Speed\") +\n  ggtitle(\"What speeds do the different players in the coverage team move at ?\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4923d41b3577c92f987df75e4961fbe3b1d06301"},"cell_type":"code","source":"#Let's see which position in the return team is most susceptible to concussions\nvideo_review %>%\n  select(Role,player_speedbins) %>%\n  filter(Role %in% punt_return) %>%\n  ggplot(mapping=aes(x=Role,fill=factor(player_speedbins),y = (..count..)/sum(..count..))) + \n  geom_bar() + \n  xlab(\"Return Role\") +\n  ylab(\"Percent\") +\n  labs(fill=\"Player Speed\") +\n  scale_y_continuous(labels = scales::percent) +\n  ggtitle(\"What speeds do the different players in the coverage team move at ?\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"cb7ffc5dcb377951a2e58514d0cd5c7eb3c9fc9d"},"cell_type":"code","source":"video_review$Speed_differentials = video_review$Max_speeds - video_review$Partner_Max_speeds\nvideo_review$Fast_or_slow = ifelse(video_review$Speed_differentials %in% NA,'No Collision',ifelse(video_review$Speed_differentials < 0,'Slower','Faster'))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"52233d2375253ca68b128664765ddc86396099d8"},"cell_type":"code","source":"video_review %>%\n    select(Fast_or_slow,Special_team) %>%\n    ggplot(mapping=aes(x=as.vector(Fast_or_slow),y = (..count..)/sum(..count..),fill=factor(Special_team))) + \n    geom_bar()+\n    ylab(\"Percent\") +\n    xlab(\"Faster or Slower ?\") +\n    labs(fill=\"Special Team\") +\n    scale_y_continuous(labels = scales::percent) +\n    ggtitle(\"Was the concussion player faster than the player he collided with ?\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a37390e42626ae2e3a02abbe2d418390483b2a56"},"cell_type":"code","source":"video_review %>%\n    select(Speed_differentials) %>%\n    ggplot(mapping=aes(x=abs(as.vector(Speed_differentials)))) +\n    stat_density() +\n    xlab(\"Speed Differentials\") +\n    ggtitle(\"What were the speed differentials between players and their partners ?\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"35d187f529408a38ae24a1174a0e4b33739dbdb9"},"cell_type":"markdown","source":"Faster = 48.65\nSlower = 40.54\n\nquite a high propoprtion of the speed differentials are over 1 mph and quite a siginificant proportional are at 4/5 and even 6 miles per hour."}],"metadata":{"kernelspec":{"display_name":"R","language":"R","name":"ir"},"language_info":{"mimetype":"text/x-r-source","name":"R","pygments_lexer":"r","version":"3.4.2","file_extension":".r","codemirror_mode":"r"}},"nbformat":4,"nbformat_minor":1}