Skip to content

Commit

Permalink
Create Fantasy-Football.R
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelR90 committed Nov 1, 2015
1 parent a239888 commit 1d1941e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Fantasy-Football.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
library('ggplot2')
#-------------------------------------------------------
#------- Data Incubator Challenge: Question 3 ----------
#-------- Fantasy Football and Data Science ------------
#-------------------------------------------------------
rm(list = ls())
gc(verbose = FALSE)

# Load the data into a dataframe -----------------------
ff_data <- read.csv("FF.csv", header = TRUE)
str(ff_data)

# Scatterplot of players fantasy points vs cost --------
qplot(Cost, FP, data = ff_data, shape = Position, color = Position,
ylab = "Fantasy Points", xlab = "Cost", main = "Fantasy Points vs Cost")

# Boxplot showing points distributions across-----------
# Plot 1 -----------------------------------------------
qplot(Position, FP, data = ff_data, geom = "boxplot", fill = Position,
ylab = "Fantasy Points", xlab = "Position",
main = "Fantasy Points Distributions Across Positions")

# Retrieve QB data ------------------------------------
QB_data <- ff_data[ff_data$Position == "QB", c('Player', 'FP', 'Cost')]
str(QB_data)

# Compute QB average fantasy points and average cost ---
QB_avg <- apply(QB_data[,c("FP", "Cost")],2,'mean')

# Determine possible QB sleepers using averages---------
QB_data$Sleeper <- QB_data$FP > QB_avg["FP"] & QB_data$Cost < QB_avg["Cost"]
str(QB_data)

# Plot of possible QB sleepers comparing them to rest --
# Plot 2 -----------------------------------------------
qplot(Cost, FP, data = QB_data, shape = Sleeper, color = Sleeper,
ylab = "Fantasy Points", xlab = "Cost ($)", main = "Potential Quaterback Sleepers")

0 comments on commit 1d1941e

Please sign in to comment.