---
title: "NFL Draft Weight Exploration"
author: "Alex Bresler"
output:
flexdashboard::flex_dashboard:
theme: flatly
social: menu
dev: svg
source_code: embed
self_contained: FALSE
lib_dir: lib
---
```{r setup, include=FALSE}
library(flexdashboard)
library(readr)
library(dplyr)
library(ggplot2) # devtools::install_github("hadley/ggplot2")
library(hrbrmisc) # devtools::install_github("hrbrmstr/hrbrmisc") -- to use theme_hrbrmstr_my() you need Myriad Fonts Installed
library(viridis)
library(magrittr)
library(stringr)
all_nfl_draft_weights <-
'https://gist.githubusercontent.com/abresler/a679be59d94b1925f9eb7ee0d4448525/raw/48dc8d38a831f0e7d52c7b3031101665fb08e848/all_nfl_weight_data.csv' %>%
read_csv() %>%
mutate(decade = (year.draft %/% 10 ) * 10)
summary_by_pos <-
all_nfl_draft_weights %>%
dplyr::rename(year = year.draft) %>%
group_by(year, type.pos, decade) %>%
summarise_each_(funs(mean(., na.rm = T), median(., na.rm = T), min(., na.rm = T), max(., na.rm = T), length), vars = 'weight.lbs') %>%
dplyr::rename(count = length) %>%
dplyr::select(decade, everything()) %>%
ungroup
get_hrbstyle_nfl_draft_plot <-
function(position_group = "Quarterback") {
plot_data <-
summary_by_pos %>%
dplyr::filter(type.pos %in% position_group)
all_pos_data <-
all_nfl_draft_weights %>% dplyr::rename(year = year.draft) %>%
dplyr::filter(!weight.lbs %>% is.na) %>% dplyr::filter(type.pos %in% position_group)
plot <-
plot_data %>%
ggplot() +
geom_segment(aes(
x = year,
xend = year,
y = min,
yend = max,
color = year
),
size = 0.2) +
geom_jitter(
data = all_pos_data,
aes(x = year, y = weight.lbs),
color = "white",
shape = ".",
size = 0.1,
alpha = .55
) +
scale_x_continuous(name = "Draft Year", expand = c(0, 0.5),
) +
scale_y_continuous(
name = 'Weight in lbs.',
) +
scale_color_viridis(option = "C") +
facet_wrap( ~ decade, nrow = 1, scales = "free_x") +
labs(title = paste0(paste0(position_group, collapse = ' '), ' Draft Weights') %>% stringr::str_trim(),
"NFL Offensive Lineman Draft Weights",
subtitle = "Upper: Heaviest Player, Lower: Lighest Player, White Dot: Player's Weight",
caption = "Pro-football Reference (www.pro-football-reference.com)\nSource code available at gist.github.com/abresler") +
theme_hrbrmstr_my(grid = "XY") +
theme(panel.background = element_rect(fill = "black", color = "#2b2b2b", size =
0.15)) +
theme(panel.margin = margin(0, 0, 0, 0)) +
theme(panel.grid.major.y = element_line(color = "#b2182b", size =
0.25)) +
theme(strip.text = element_text(hjust = 0.5)) +
theme(axis.title.x = element_text(hjust = 0, margin = margin(t = -10))) +
theme(axis.text.x = element_blank()) +
theme(axis.text.y = element_text(size = 12, color = "#b2182b")) +
theme(legend.position = "none") +
theme(plot.margin = margin(10, 10, 10, 10)) +
theme(plot.caption = element_text(margin = margin(t = -6)))
return(plot)
}
```
Offense
=====================================================================
Column {.tabset}
-------------------------------------
### OL
```{r}
get_hrbstyle_nfl_draft_plot(position_group = "Offensive Line")
```
### QB
```{r}
get_hrbstyle_nfl_draft_plot(position_group = "Quarterback")
```
### WR
```{r}
get_hrbstyle_nfl_draft_plot(position_group = "Recieiver")
```
### TE
```{r}
get_hrbstyle_nfl_draft_plot(position_group = "Tight End")
```
### RB
```{r}
get_hrbstyle_nfl_draft_plot(position_group = "Running Back")
```
### FB
```{r}
get_hrbstyle_nfl_draft_plot(position_group = "Fullback")
```
Defense
=====================================================================
Column {.tabset}
-------------------------------------
### DL
```{r}
get_hrbstyle_nfl_draft_plot(position_group = "Defensive Line")
```
### LB
```{r}
get_hrbstyle_nfl_draft_plot(position_group = "Linebacker")
```
### S/CB
```{r}
get_hrbstyle_nfl_draft_plot(position_group = "Secondary")
```
Special Teams
=====================================================================
Column {.tabset}
-------------------------------------
### K
```{r}
get_hrbstyle_nfl_draft_plot(position_group = "Kicker")
```
### P
```{r}
get_hrbstyle_nfl_draft_plot(position_group = "Punter")
```