-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathREADME.Rmd
More file actions
175 lines (135 loc) · 8.73 KB
/
Copy pathREADME.Rmd
File metadata and controls
175 lines (135 loc) · 8.73 KB
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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# **cfbplotR** <a href='https://cfbplotR.sportsdataverse.org/'><img src='https://raw.githubusercontent.com/sportsdataverse/cfbplotR/main/man/figures/logo.png' align="right" width="25%" min-width="120px" /></a>
<!-- badges: start -->
<!-- [](https://CRAN.R-project.org/package=cfbplotR) -->
<!-- [](https://CRAN.R-project.org/package=cfbplotR) -->
[](https://github.com/sportsdataverse/cfbplotR/)
[](https://github.com/sportsdataverse/cfbplotR/actions/workflows/R-CMD-check.yaml)
[](https://github.com/sportsdataverse/cfbplotR/actions/workflows/pkgdown.yaml)
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[](https://sportsdataverse.r-universe.dev/cfbplotR)
[](https://github.com/sportsdataverse/cfbplotR/graphs/contributors)
[](https://twitter.com/JaredDLee)
[](https://twitter.com/SportsDataverse)
<!-- badges: end -->
[**`cfbplotR`**](https://cfbplotR.sportsdataverse.org/) is an R package for plotting College Football (CFB) team logos, player headshots, wordmarks, and conference logos in [**`ggplot2`**](https://ggplot2.tidyverse.org/) graphics and [**`gt`**](https://gt.rstudio.com/) tables. It is built on the [**`ggpath`**](https://mrcaseb.github.io/ggpath/) package and follows the conventions established by [nflplotR](https://nflplotr.nflverse.com/) — porting that proven approach to college football.
Part of the [SportsDataverse](https://sportsdataverse.org/) family of R packages for sports analytics.
## **Installation**
You can install the development version of [**`cfbplotR`**](https://github.com/sportsdataverse/cfbplotR) from [GitHub](https://github.com/sportsdataverse/cfbplotR) with:
```r
# using the pak package (recommended):
if (!requireNamespace('pak', quietly = TRUE)){
install.packages('pak')
}
pak::pak("sportsdataverse/cfbplotR")
```
```r
# or using the devtools package:
if (!requireNamespace('devtools', quietly = TRUE)){
install.packages('devtools')
}
devtools::install_github(repo = "sportsdataverse/cfbplotR")
```
```r
# or clone and install locally
git clone https://github.com/sportsdataverse/cfbplotR
cd cfbplotR
Rscript -e "pak::local_install()" # or: Rscript -e "devtools::install()"
```
## **Usage**
[You can follow the package tutorial for several detailed examples.](https://cfbplotR.sportsdataverse.org/articles/tutorial.html)
The core function `geom_cfb_logos()` adds CFB team logos to a ggplot. Axis helpers (`scale_x_cfb()`, `scale_y_cfb()`) replace axis labels with team logos via `element_cfb_logo()`. The `gt_fmt_cfb_logo()` helper adds logos inside `gt` table cells.
```{r logos-grid, eval = FALSE}
library(cfbplotR)
library(ggplot2)
# grab the first 32 valid team abbreviations
team <- valid_team_names()[1:32]
df <- data.frame(
a = rep(1:8, 4),
b = sort(rep(1:4, 8), decreasing = TRUE),
teams = team
)
ggplot(df, aes(x = a, y = b)) +
geom_cfb_logos(aes(team = teams), width = 0.075) +
geom_label(aes(label = teams), nudge_y = -0.35, alpha = 0.5) +
theme_void()
```
```{r axis-logos, eval = FALSE}
library(cfbplotR)
library(ggplot2)
# logos on the x-axis via scale_x_cfb() + element_cfb_logo()
df2 <- data.frame(
team = c("Alabama", "Georgia", "Ohio State", "Michigan"),
score = c(42, 38, 35, 30)
)
ggplot(df2, aes(x = team, y = score)) +
geom_col(aes(fill = team), show.legend = FALSE) +
scale_x_cfb(labels = "logo") +
theme_minimal() +
theme(
axis.text.x = element_cfb_logo(size = 1)
)
```
```{r gt-logos, eval = FALSE}
library(cfbplotR)
library(gt)
# logos inside a gt table
data.frame(
team = c("Alabama", "Georgia", "Ohio State"),
wins = c(13, 12, 11)
) |>
gt() |>
gt_fmt_cfb_logo(columns = "team")
```
## **Documentation**
For more information on the package and function reference, please see
the [**`cfbplotR`** documentation website](https://cfbplotR.sportsdataverse.org).
## **The SportsDataverse**
`cfbplotR` is part of the [**SportsDataverse**](https://sportsdataverse.org/), a family of open-source R, Python, and Node.js packages for sports data.
| Package | Sport / Scope |
|---|---|
| [**cfbfastR**](https://cfbfastR.sportsdataverse.org/) | College football |
| [**hoopR**](https://hoopR.sportsdataverse.org/) | Men's basketball (NBA & NCAA) |
| [**wehoop**](https://wehoop.sportsdataverse.org/) | Women's basketball (WNBA & NCAA) |
| [**fastRhockey**](https://fastRhockey.sportsdataverse.org/) | Hockey (NHL & PWHL) |
| [**baseballr**](https://billpetti.github.io/baseballr/) | Baseball (MLB, MiLB, NCAA) |
| [**oddsapiR**](https://oddsapiR.sportsdataverse.org/) | Sports betting odds (The Odds API) |
| [**sportsdataverse-R**](https://r.sportsdataverse.org/) | Umbrella R metapackage |
| [**sportsdataverse-py**](https://py.sportsdataverse.org/) · [**sportsdataverse.js**](https://js.sportsdataverse.org/) | Python & Node.js |
See the full ecosystem at [sportsdataverse.org](https://sportsdataverse.org/).
## Follow [cfbplotR](https://twitter.com/cfbfastR) and the [SportsDataverse](https://twitter.com/SportsDataverse) on Twitter and star this repo
[](https://twitter.com/JaredDLee)
[](https://twitter.com/SportsDataverse)
[](https://github.com/sportsdataverse/cfbplotR/stargazers/)
## **Our Authors**
- [Jared Lee](https://twitter.com/JaredDLee) </br>
<a href="https://twitter.com/JaredDLee" target="blank"><img src="https://img.shields.io/twitter/follow/JaredDLee?color=blue&label=%40JaredDLee&logo=twitter&style=for-the-badge" alt="@JaredDLee" /></a>
<a href="https://github.com/Kazink36" target="blank"><img src="https://img.shields.io/github/followers/Kazink36?color=eee&logo=Github&style=for-the-badge" alt="@Kazink36" /></a>
- [Saiem Gilani](https://twitter.com/saiemgilani) </br>
<a href="https://twitter.com/saiemgilani" target="blank"><img src="https://img.shields.io/twitter/follow/saiemgilani?color=blue&label=%40saiemgilani&logo=twitter&style=for-the-badge" alt="@saiemgilani" /></a>
<a href="https://github.com/saiemgilani" target="blank"><img src="https://img.shields.io/github/followers/saiemgilani?color=eee&logo=Github&style=for-the-badge" alt="@saiemgilani" /></a>
- [Sebastian Carl](https://twitter.com/mrcaseb) </br>
<a href="https://twitter.com/mrcaseb" target="blank"><img src="https://img.shields.io/twitter/follow/mrcaseb?color=blue&label=%40mrcaseb&logo=twitter&style=for-the-badge" alt="@mrcaseb" /></a>
<a href="https://github.com/mrcaseb" target="blank"><img src="https://img.shields.io/github/followers/mrcaseb?color=eee&logo=Github&style=for-the-badge" alt="@mrcaseb" /></a>
## **Citations**
To cite the [**`cfbplotR`**](https://cfbplotR.sportsdataverse.org/) R package in publications, use:
BibTex Citation
```bibtex
@misc{lee_carl_gilani_cfbplotR,
author = {Lee, Jared and Gilani, Saiem and Carl, Sebastian},
title = {cfbplotR: The SportsDataverse's R Package for College Football Plotting.},
url = {https://cfbplotR.sportsdataverse.org},
year = {2021}
}
```