---
title: "Workout Comparisons"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
source_code: embed
---
```{r setup, include=FALSE}
# Libraries
library(flexdashboard)
library(reshape2)
library(ggplot2)
library(ggthemes)
library(viridisLite)
library(tidyverse)
# Inputs
playerDemos <- data.frame(Name='Omarion Hampton',
Pos = 'RB',
Ht = paste(72 %/% 12, 'ft', 72 %% 12, 'in'),
Wt = '221',
Edu = 'North Carolina')
playerEvals <- data.frame(Forty = 4.46,
Vertical = 38,
BenchReps = 18,
BroadJump = 130,
Cone = 6.84,
Shuttle = 4.40)
# Read in the data
history <- read.csv('https://raw.githubusercontent.com/kwartler/NLP_SportsAnalytics/master/football_case_data/historical.csv')
print(head(history)) # Preview the data
# Clean, remove NAs rather than impute
history <- history[complete.cases(history),]
evals <- history[,c('Forty','Vertical','BenchReps','BroadJump','Cone','Shuttle','draftStatus','Pos')]
evals$draftStatus <- as.factor(evals$draftStatus)
evals <- melt(evals)
# Filter data for the player's position
plotData <- subset(evals, as.character(evals$Pos)==
as.character(playerDemos[1,2]))
plotData <- split(plotData, plotData$variable)
# Compute mean values for draft statuses
muData <- lapply(plotData, function(x) aggregate(value ~ draftStatus, data = x, FUN = mean))
# Color Blind safe colors
valueBoxCols <- viridis(6)
```
## Row
### Player Name
```{r name}
valueBox(value=playerDemos$Name, icon="fa-user", color=valueBoxCols[1])
```
### Position
```{r}
valueBox(value=playerDemos$Pos, icon="fa-football-ball", color=valueBoxCols[2])
```
### Ht
```{r}
valueBox(value=playerDemos$Ht, icon="fa-ruler-vertical", color=valueBoxCols[3])
```
### Wt
```{r}
valueBox(value=playerDemos$Wt, icon="fa-weight", color=valueBoxCols[4])
```
### Edu
```{r}
valueBox(value=playerDemos$Edu, icon="fa-school", color=valueBoxCols[5])
```
## Row
### Forty
```{r forty}
statNum <- 1
ggplot(plotData[[statNum]], aes(x = value, fill = draftStatus)) +
geom_density(alpha=0.75) +
geom_vline(aes(xintercept=playerEvals[[statNum]]), color='black') +
geom_vline(data=muData[[statNum]], aes(xintercept = value, color=draftStatus), linetype="dashed") +
scale_color_manual(values=c('darkgreen','darkred')) +
scale_fill_viridis_d('Draft Status', option = 'C') +
theme_hc() +
theme(axis.title.y = element_blank(), axis.text.y = element_blank(), axis.ticks.y = element_blank())
```
### Vertical
```{r vert}
statNum <- 2
ggplot(plotData[[statNum]], aes(x = value, fill = draftStatus)) +
geom_density(alpha=0.75) +
geom_vline(aes(xintercept=playerEvals[[statNum]]), color='black') +
geom_vline(data=muData[[statNum]], aes(xintercept = value, color=draftStatus), linetype="dashed") +
scale_color_manual(values=c('darkgreen','darkred')) +
scale_fill_viridis_d('Draft Status', option = 'C') +
theme_hc() +
theme(axis.title.y = element_blank(), axis.text.y = element_blank(), axis.ticks.y = element_blank())
```
### Bench Reps
```{r reps}
statNum <- 3
ggplot(plotData[[statNum]], aes(x = value, fill = draftStatus)) +
geom_density(alpha=0.75) +
geom_vline(aes(xintercept=playerEvals[[statNum]]), color='black') +
geom_vline(data=muData[[statNum]], aes(xintercept = value, color=draftStatus), linetype="dashed") +
scale_color_manual(values=c('darkgreen','darkred')) +
scale_fill_viridis_d('Draft Status', option = 'C') +
theme_hc() +
theme(axis.title.y = element_blank(), axis.text.y = element_blank(), axis.ticks.y = element_blank())
```
## Row
### Broad Jump
```{r jump}
statNum <- 4
ggplot(plotData[[statNum]], aes(x = value, fill = draftStatus)) +
geom_density(alpha=0.75) +
geom_vline(aes(xintercept=playerEvals[[statNum]]), color='black') +
geom_vline(data=muData[[statNum]], aes(xintercept = value, color=draftStatus), linetype="dashed") +
scale_color_manual(values=c('darkgreen','darkred')) +
scale_fill_viridis_d('Draft Status', option = 'C') +
theme_hc() +
theme(axis.title.y = element_blank(), axis.text.y = element_blank(), axis.ticks.y = element_blank())
```
### Cone
```{r cone}
statNum <- 5
ggplot(plotData[[statNum]], aes(x = value, fill = draftStatus)) +
geom_density(alpha=0.75) +
geom_vline(aes(xintercept=playerEvals[[statNum]]), color='black') +
geom_vline(data=muData[[statNum]], aes(xintercept = value, color=draftStatus), linetype="dashed") +
scale_color_manual(values=c('darkgreen','darkred')) +
scale_fill_viridis_d('Draft Status', option = 'C') +
theme_hc() +
theme(axis.title.y = element_blank(), axis.text.y = element_blank(), axis.ticks.y = element_blank())
```
### Shuttle
```{r shuttle}
statNum <- 6
ggplot(plotData[[statNum]], aes(x = value, fill = draftStatus)) +
geom_density(alpha=0.75) +
geom_vline(aes(xintercept=playerEvals[[statNum]]), color='black') +
geom_vline(data=muData[[statNum]], aes(xintercept = value, color=draftStatus), linetype="dashed") +
scale_color_manual(values=c('darkgreen','darkred')) +
scale_fill_viridis_d('Draft Status', option = 'C') +
theme_hc() +
theme(axis.title.y = element_blank(), axis.text.y = element_blank(), axis.ticks.y = element_blank())
```