An open API service indexing awesome lists of open source software.

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).

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}

knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)

```

# wnblr  

Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.
[![GitHub latest commit](https://img.shields.io/github/last-commit/jacquietran/wnblr)](https://github.com/badges/shields)
[![GitHub open issues](https://img.shields.io/github/issues-raw/jacquietran/wnblr)](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")
```
## Examples

There'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!!