Dev Data Products

Course Project

1) Overview

For this practice the 2014 NFL Season data were selected to make the graphs using Plotly.

The data can be found in the link:

https://www.ibm.com/communities/analytics/watson-analytics-blog/analyze-nfl-data-for-the-big-game/

2) Libraries

library(plotly)
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

3) Data preparation

if(!file.exists("SportsData_NFL_2014_REG_PST_players.csv")){
  myURL = paste("https://community.watsonanalytics.com/wp-content/uploads/2015/01/SportsData_NFL_2014_REG_PST_players.csv?cm_mc_uid=12463795688815406555121&cm_mc_sid_50200000=52257421540655512164",sep = "")
  
  dir = "SportsData_NFL_2014_REG_PST_players.csv"
  download.file(myURL, dir, mode="wb")  
}


dtPlayer <- read.csv("SportsData_NFL_2014_REG_PST_players.csv", na.strings = c("NA", "#DIV/0!", ""))


mostTouchDownTeam <-  dtPlayer %>%
  select(Team, Total.TD) %>%
  group_by(Team) %>%
  summarise(tdCant = sum(Total.TD)) %>%
  arrange(-tdCant) %>%
  head(5)

touchDwnXteam <- dtPlayer %>%
  filter(Team %in% mostTouchDownTeam$Team) %>%
  select(Week, Team, Total.TD) %>%
  group_by(Week, Team) %>%
  summarise(tdCant = sum(Total.TD))

4) Touchdown per Team

Based on 2014 NFL Season, with the next graph we will try to show how was the TD’s distribution on the season by team.

plot_ly(data = as.data.frame(dtPlayer %>%
                               select(Team, Total.TD) %>%
                               group_by(Team) %>%
                               summarise(tdCant = sum(Total.TD)) %>%
                               arrange(-tdCant))
        , x = ~Team, y = ~tdCant
        , type = 'bar', orientation = 'v') %>% 
  layout(title = "Touchdowns per Team in 2014 season"
         ,xaxis = list(title="Team"), yaxis = list(title = "Touchdowns per season"))

5) Touchdown per Team

Based on 2014 NFL Season, taking the top 5 teams with most TD’s, the next graph shows the TD’s distribution per week of those teams.

plot_ly(
  data = as.data.frame(touchDwnXteam)
  , x = ~Week, y = ~tdCant, split = ~Team, type = "scatter", mode = "lines"
) %>% layout(title = "Most Touchdowns per Team by Week"
             ,xaxis = list(title="Week Number"), yaxis = list(title = "TouchDowns"))