https://github.com/jacquietran/wnblr
An R package containing game stats from the Women's National Basketball League (WNBL).
https://github.com/jacquietran/wnblr
basketball data r r-package wnbl
Last synced: 4 months ago
JSON representation
An R package containing game stats from the Women's National Basketball League (WNBL).
- Host: GitHub
- URL: https://github.com/jacquietran/wnblr
- Owner: jacquietran
- License: other
- Created: 2021-11-16T05:39:38.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-05T03:44:24.000Z (about 3 years ago)
- Last Synced: 2024-08-13T07:12:56.345Z (6 months ago)
- Topics: basketball, data, r, r-package, wnbl
- Language: R
- Homepage:
- Size: 27.6 MB
- Stars: 10
- Watchers: 2
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - jacquietran/wnblr - An R package containing game stats from the Women's National Basketball League (WNBL). (R)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)```
# wnblr
![]()
![]()
[](https://github.com/badges/shields)
[](https://github.com/jacquietran/wnblr/issues)> ~~Buyer~~ **Coder beware:** As of Dec 2021, this package is undergoing major re-development. The next version will introduce many improvements but also breaking changes.
The `wnblr` package contains a range of game statistics from the Australian [**Women's National Basketball League (WNBL)**](https://www.wnbl.com.au):
- `box_scores`: Team-level box scores, with all your usual basketball box score metrics like points scored, field goals made / attempted, free throws made / attempted, rebounds, turnovers, and the like.
- `box_scores_detailed`: Player-level box scores.
- `pbp`: Play-by-play data.
- `shots`: Shots data, primarily containing XY shot locations.## Installation
Install the development version of `wnblr` from GitHub with:
``` r
# install.packages("remotes")
remotes::install_github("jacquietran/wnblr")
```
## ExamplesThere's lots to work with - for example, here's a quick look at the `shots` data:
```{r summarise_shots, message = FALSE}
# Load libraries
library(wnblr)
library(dplyr)# Frequency of shot types attempted in the 2020 season
shots %>%
filter(season == 2020) %>%
select(sub_type, shot_result) %>%
group_by(sub_type) %>%
summarise(n = n()) %>%
ungroup() %>%
arrange(desc(n))```
With a little bit of elbow grease, you can move neatly from data to plot, too:
```{r plot, dpi=320, message = FALSE}
# Load libraries
library(ggplot2)
library(showtext)# Tidy data
magbegor <- box_scores_detailed %>%
filter(scoreboard_name == "E. Magbegor") %>%
select(season, contains("field_goals")) %>%
group_by(season) %>%
summarise(
`Field goals made` = round(mean(field_goals_made), 1),
`Field goals attempted` = round(mean(field_goals_attempted), 1),
`Field goal %` = round(mean(field_goals_percentage), 1)) %>%
ungroup() %>%
tidyr::pivot_longer(
cols = c(`Field goals made`,
`Field goals attempted`,
`Field goal %`),
names_to = "key",
values_to = "value") %>%
mutate(
key = factor(
key, levels = c("Field goals made",
"Field goals attempted",
"Field goal %")))# Import Google Fonts
font_add_google(name = "Patua One", family = "patua")
font_add_google(name = "Source Sans Pro", family = "source")# Build plot
showtext_auto()
# After building the plot, run showtext_auto(FALSE) to close off
ggplot(
magbegor,
aes(x = season, y = value, group = key, fill = key)) +
facet_wrap(~key, nrow = 1, scales = "free_y") +
geom_bar(stat = "identity") +
scale_fill_manual(values = c("#FFC53D", "#688d3a", "#0E4735")) +
labs(
title = "Ezi Magbegor: WNBL shooting averages from 2017-2020",
x = "Season", y = NULL,
caption = "Data source: {wnblr} & WNBL.com.au | Plot: @jacquietran") +
ggdark::dark_mode() +
theme(
legend.position = "none",
text = element_text(
colour = "#FFFFFF", family = "source", size = 48),
plot.title = element_text(
family = "patua", margin=margin(0,0,15,0)),
plot.caption = element_text(margin=margin(15,0,0,0)))```
```{r, echo = FALSE}
showtext_auto(FALSE)
```
## Known issues
Game data is missing or wildly incomplete for some games in most of the seasons from 2014/2015 to 2020, as documented [here](https://github.com/jacquietran/wnblr/issues/23). If anyone has leads on where to find live stats from the games listed as "missing", feel free to log an issue and let me know!
## Hex logos
Courtesy of [**@PythonUnicornCoder**](https://github.com/PythonUnicornCoder) - thank you!!