https://github.com/camdenk/mlbplotr
R package to easily plot MLB logos
https://github.com/camdenk/mlbplotr
baseball ggplot2 r rstats sportsdataverse
Last synced: 9 months ago
JSON representation
R package to easily plot MLB logos
- Host: GitHub
- URL: https://github.com/camdenk/mlbplotr
- Owner: camdenk
- License: other
- Created: 2022-02-11T01:23:08.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-09-02T20:29:27.000Z (10 months ago)
- Last Synced: 2025-09-02T21:22:02.020Z (10 months ago)
- Topics: baseball, ggplot2, r, rstats, sportsdataverse
- Language: R
- Homepage: https://camdenk.github.io/mlbplotR/
- Size: 241 MB
- Stars: 22
- Watchers: 2
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
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%",
dpi = 600
)
```
[](https://lifecycle.r-lib.org/articles/stages.html)
[](https://github.com/camdenk/mlbplotR/actions/workflows/R-CMD-check.yaml)
The code for this package was copied heavily from [nflplotR](https://nflplotr.nflverse.com/index.html) with minor changes to support Major League Baseball logos.
The goal of mlbplotR is to provide functions and geoms that help with visualizations of MLB related analysis. It provides ggplot2 geoms that do the heavy lifting of plotting MLB logos in high quality, with correct aspect ratio, and possible transparency.
## Installation
The easiest way to get mlbplotR is to install it from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("mlbplotR")
```
To get a bug fix or use a feature from the development version, you can install the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("camdenk/mlbplotR")
```
## Usage
Let's plot every team on a grid with some extra customization:
```{r every-team, message = FALSE}
library(mlbplotR)
library(ggplot2)
library(dplyr)
teams_colors_logos <- mlbplotR::load_mlb_teams() |>
dplyr::filter(!team_abbr %in% c("AL", "NL", "MLB")) |>
dplyr::mutate(
a = rep(1:6, 5),
b = sort(rep(1:5, 6), decreasing = TRUE)
)
ggplot2::ggplot(teams_colors_logos, aes(x = a, y = b)) +
mlbplotR::geom_mlb_logos(aes(team_abbr = team_abbr), width = 0.075) +
ggplot2::geom_label(aes(label = team_abbr), nudge_y = -0.35, alpha = 0.5) +
ggplot2::theme_void()
```
There is a [getting started guide](https://camdenk.github.io/mlbplotR/articles/mlbplotR.html) that will walk you through more use cases for the package.
## Contributing
- [Open an issue](https://github.com/camdenk/mlbplotR/issues/new/choose) if you'd like to request specific data or report a bug/error.
