-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathREADME.Rmd
189 lines (161 loc) · 4.21 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# fantasypros
<!-- badges: start -->
[![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing)
<!-- badges: end -->
The goal of `fantasypros` is to provide easy and reproducable access to data
provided on [fantasypros](https://www.fantasypros.com). The intital focus is on
NFL and fantasy football data, but other sports are planned to be added
## Installation
You can install the released version of fantasypros from [CRAN](https://CRAN.R-project.org) with:
``` r
# not on CRAN
install.packages("fantasypros")
```
And the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("jpiburn/fantasypros")
```
## Example
This is a basic example which shows you how to solve a common problem:
## Visualizing Expert Consensus Ranking
```{r rb-erc-chart, fig.height=8, message=FALSE, warning=FALSE}
library(fantasypros)
library(ggplot2)
library(dplyr)
fp_draft_rankings("RB") %>%
filter(rank <= 40) %>%
ggplot(
aes(x = avg, y = adp, colour = factor(tier), label = player)
) +
geom_abline(
slop = 1,
intercept = 0,
linetype = 2,
color = "grey"
) +
geom_errorbarh(
aes(xmin = avg - std_dev, xmax = avg + std_dev),
height = 0,
alpha = 0.6,
size = 0.9,
show.legend = FALSE
) +
geom_point(size = 1.5) +
scale_x_reverse(
breaks = c(1, seq(10,70, 10))
) +
scale_y_reverse(
breaks = c(1, seq(10,60, 10))
) +
ggsci::scale_color_npg() +
hrbrthemes::theme_ipsum_rc(
base_size = 10,
axis_title_size = 9,
plot_title_size = 14
) +
labs(
title = "RB Expert Consensus Rank vs Average Draft Position",
colour = "Tier",
x = "Expert Consensus Rank",
y = "Average Draft Position",
caption = "Data: fantasypros.com"
) +
geom_text(
aes(x = avg + std_dev),
size = 2,
nudge_x = -3.5,
show.legend = FALSE,
fontface = "bold"
) +
geom_text(
aes(x = 10, y = 35), label = "Under\nDrafted", color = "light grey",
size = 8, family = "Roboto Condensed", fontface = "italic"
) +
geom_text(
aes(x = 45, y = 10), label = "Over\nDrafted", color = "light grey",
size = 8, family = "Roboto Condensed", fontface = "italic"
) +
theme(
legend.position = "bottom",
) +
guides(
colour = guide_legend(nrow = 1)
)
```
## Team Target Distributions
```{r target-dist, message=FALSE, warning=FALSE, fig.height=7}
library(fantasypros)
library(tidyverse)
library(ggplot2)
fp_team_targets(season = 2018) %>%
select(
team,
ends_with("percent")
) %>%
mutate(
team = forcats::fct_reorder(team, rb_percent)
) %>%
gather("position", "percent", -team) %>%
mutate(
pos = factor(
position,
levels = c("te_percent", "wr_percent", "rb_percent"),
labels = c("TE", "WR", "RB")
)
) %>%
ggplot() +
geom_col(
aes(team, percent, fill = pos), alpha = 0.9
) +
scale_x_discrete(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0)) +
ggsci::scale_fill_jama() +
hrbrthemes::theme_ipsum_rc() +
coord_flip() +
labs(
title = "Team Target Distribution",
fill = NULL,
y = "Target %",
x = NULL,
caption = "Data: fantasypros.com"
) +
theme(
legend.position = "bottom"
)
```
## Season Stats
```{r season-stats, message=FALSE}
library(fantasypros)
fp_stats("QB", season = 2018, start_week = 3, end_week = 8)
```
## Weekly Snap Counts
```{r snap-counts, message=FALSE}
library(fantasypros)
fp_snap_counts(season = 2018)
fp_snap_counts(pos = "defense", season = 2018, percentage = TRUE)
```
## Detailed Snap Analysis
```{r snap-analysis, message=FALSE}
library(fantasypros)
# all offensive positions for weeks 5-9 of the 2018 season
fp_snap_analysis(season = 2018, start_week = 5, end_week = 9)
```
## Weekly Targets
```{r targets, message=FALSE}
library(fantasypros)
# total targets for TE's in the 2014 season
fp_targets(pos = "TE", season = 2014)
```