teamcolors

an R package providing color palettes for pro sports teams

https://github.com/beanumber/teamcolors

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 2 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
    3 of 10 committers (30.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.5%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

an R package providing color palettes for pro sports teams

Basic Info
  • Host: GitHub
  • Owner: beanumber
  • Language: R
  • Default Branch: master
  • Size: 5.98 MB
Statistics
  • Stars: 48
  • Watchers: 5
  • Forks: 13
  • Open Issues: 9
  • Releases: 2
Created about 10 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog

README.Rmd

---
output:
  github_document:
    html_preview: true
---
# teamcolors 


[![R-CMD-check](https://github.com/beanumber/teamcolors/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/beanumber/teamcolors/actions/workflows/R-CMD-check.yaml)
[![CRAN status](https://www.r-pkg.org/badges/version/teamcolors)](https://cran.r-project.org/package=teamcolors)



An R package providing color palettes for pro and amateur sports teams. The palettes are provided by [Jim Neilsen's Team Colors website](http://jim-nielsen.com/teamcolors/) and offered with only minimal alterations. NCAA colors come from [teamcolorcodes.com](https://teamcolorcodes.com/), via the [ncaahoopR](https://github.com/lbenz730/ncaahoopR) package.
Other sports include the [Women's National Basketball Association](https://wnba.com), [National Women's Soccer League](https://nwsl.com), and the [Canadian Football League](https://cfl.com).

## Install

To install the CRAN version, use:

```{r, eval=FALSE}
install.packages(teamcolors)
```

To install the development version from GitHub, use:

```{r, eval=FALSE}
devtools::install_github("beanumber/teamcolors")
```

## Load

```{r}
library(teamcolors)
head(teamcolors)
```

## Show palettes

Sometimes you need to work with a named vector of colors. Other times you can use the built-in `scale_color_teams()` and `scale_color_fill()` functions. 

```{r palettes}
league_pal("nba")
```

## Plot

In baseball, [Pythagorean expectation](https://en.wikipedia.org/wiki/Pythagorean_expectation) relates expected winning percentage to runs allowed and runs scored. How well does it work? 

```{r pythag, message=FALSE}
library(Lahman)
library(tidyverse)
pythag <- Teams %>%
  filter(yearID == 2016) %>%
  select(name, teamID, yearID, W, L, R, RA) %>%
  mutate(
    wpct = W / (W + L), exp_wpct = 1 / (1 + (RA / R)^2),
    # note name discrepancy!
    name = ifelse(name == "Los Angeles Angels of Anaheim", "Los Angeles Angels", name)
  )
```

### `ggplot2`

```{r ggplot}
ggplot(pythag, aes(x = wpct, y = exp_wpct, color = name, fill = name)) +
  geom_abline(slope = 1, intercept = 0, linetype = 3) +
  geom_point(shape = 21, size = 3) +
  scale_fill_teams(guide = FALSE) +
  scale_color_teams(2, guide = FALSE) +
  ggrepel::geom_text_repel(aes(label = teamID)) +
  scale_x_continuous("Winning Percentage", limits = c(0.3, 0.7)) +
  scale_y_continuous("Expected Winning Percentage", limits = c(0.3, 0.7)) +
  theme_light() +
  labs(
    title = "Real and Pythagorean winning % by team",
    subtitle = paste(first(pull(pythag, yearID)), "MLB Season", sep = " "),
    caption = "Source: Lahman baseball database. Using teamcolors R pkg"
  ) +
  coord_equal()
```

### Base R

```{r base-r, message=FALSE}
pythag <- pythag %>%
  left_join(teamcolors, by = "name")
with(pythag, plot(wpct, exp_wpct, bg = primary, col = secondary, pch = 21, cex = 3))
```


## Key

You can see the color palettes using existing functionality from the [scales](https://github.com/r-lib/scales) package, but it won't show the names of the teams. 

```{r show_col}
scales::show_col(league_pal("mlb"), borders = league_pal("mlb", 2))
```

So, instead, use `show_team_col()`. Note that this only shows color palettes for non-NCAA teams.

```{r teamcolors, fig.height=10, fig.width=10}
show_team_col()
```


To view color palettes for college teams, use the `show_ncaa_col()` function.

```{r ncaacolors, fig.height=10, fig.width=20}
show_ncaa_col()
```


## Logos

Links to team logos are provided by (http://www.sportslogos.net/).

```{r logos}
teamcolors %>%
  filter(grepl("New Y", name)) %>%
  pull(logo) %>%
  knitr::include_graphics()
```

Note that we don't have any coverage for the EPL.

```{r}
teamcolors %>%
  group_by(league) %>%
  summarize(
    num_teams = n(),
    num_logos = sum(!is.na(logo))
  )
```

## References

For more examples see: 

- Lopez, M.J., Matthews, G.J., Baumer, B.S., "How often does the best team win? A unified approach to understanding randomness in North American sport," *The Annals of Applied Statistics*, vol. 12, no. 4, 2018, pp. 2483--2516. URL (https://doi.org/10.1214/18-AOAS1165)

To cite this package in your work, see:

```{r, eval=FALSE}
citation("teamcolors")
```

## Notes

Owner

  • Name: Ben Baumer
  • Login: beanumber
  • Kind: user
  • Location: Northampton, MA
  • Company: @SmithCollege-SDS

GitHub Events

Total
  • Issues event: 1
  • Watch event: 1
  • Push event: 7
  • Pull request event: 1
  • Fork event: 1
Last Year
  • Issues event: 1
  • Watch event: 1
  • Push event: 7
  • Pull request event: 1
  • Fork event: 1

Committers

Last synced: 12 months ago

All Time
  • Total Commits: 87
  • Total Committers: 10
  • Avg Commits per committer: 8.7
  • Development Distribution Score (DDS): 0.414
Past Year
  • Commits: 7
  • Committers: 1
  • Avg Commits per committer: 7.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Ben Baumer b****r@g****m 51
Paige PAtrick p****k@s****u 9
Gregoery J. Matthews g****s@G****l 7
Arielle Dror a****r@s****u 5
Allan a****9@g****m 4
clarajrosenberg c****g@g****m 3
Daniel H d****8 3
Martin Lefebvre M****5 2
lbenz730 l****z@y****u 2
gjm112 g****2@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 24
  • Total pull requests: 9
  • Average time to close issues: 5 months
  • Average time to close pull requests: 3 months
  • Total issue authors: 8
  • Total pull request authors: 7
  • Average comments per issue: 1.71
  • Average comments per pull request: 2.0
  • Merged pull requests: 9
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • beanumber (14)
  • gjm112 (3)
  • benjaminrobinson (1)
  • lbenz730 (1)
  • MartinLe5 (1)
  • jhackmeister (1)
  • math-mcshane (1)
  • darh78 (1)
Pull Request Authors
  • adror1 (2)
  • lbenz730 (2)
  • darh78 (1)
  • lauerjames (1)
  • clarajrosenberg (1)
  • MartinLe5 (1)
  • pep93 (1)
  • allanbutler (1)
Top Labels
Issue Labels
enhancement (2)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 268 last-month
  • Total docker downloads: 41,971
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 4
  • Total maintainers: 1
cran.r-project.org: teamcolors

Color Palettes for Pro Sports Teams

  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 268 Last month
  • Docker Downloads: 41,971
Rankings
Docker downloads count: 0.6%
Forks count: 5.1%
Stargazers count: 7.0%
Average: 17.1%
Dependent repos count: 24.0%
Dependent packages count: 28.8%
Downloads: 37.2%
Maintainers (1)
Last synced: 10 months ago

Dependencies

.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v3 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
DESCRIPTION cran
  • R >= 3.5 depends
  • dplyr * imports
  • ggplot2 * imports
  • tibble * imports
  • tidyr * imports
  • Lahman * suggests
  • testthat >= 2.1.0 suggests