| Type: | Package | 
| Title: | Color Palettes for Pro Sports Teams | 
| Version: | 0.0.4 | 
| Description: | Provides color palettes corresponding to professional and amateur, sports teams. These can be useful in creating data graphics that are themed for particular teams. | 
| Depends: | R (≥ 3.5) | 
| Imports: | dplyr, ggplot2, tibble, tidyr | 
| Suggests: | Lahman, testthat (≥ 2.1.0) | 
| License: | GPL-2 | GPL-3 [expanded from: GPL] | 
| Encoding: | UTF-8 | 
| LazyData: | true | 
| URL: | http://github.com/beanumber/teamcolors | 
| BugReports: | https://github.com/beanumber/teamcolors/issues | 
| RoxygenNote: | 7.0.2 | 
| NeedsCompilation: | no | 
| Packaged: | 2020-01-22 19:19:17 UTC; bbaumer | 
| Author: | Benjamin S. Baumer [aut, cre], Gregory J. Matthews [aut], Luke Benz [ctb], Arielle Dror [ctb], Clara Rosenberg [ctb], Paige Patrick [ctb] | 
| Maintainer: | Benjamin S. Baumer <ben.baumer@gmail.com> | 
| Repository: | CRAN | 
| Date/Publication: | 2020-01-22 22:10:03 UTC | 
Color palettes for sports teams
Description
Color palettes for sports teams
Usage
league_pal(lg, which = 1)
team_filter(pattern = ".")
team_vec(pattern = ".", which = 1)
team_pal(pattern, colors = c(1, 2))
scale_color_teams(which = 1, ...)
scale_fill_teams(which = 1, ...)
show_team_col(...)
show_ncaa_col(...)
Arguments
| lg | character vector for the league identifier | 
| which | Which set of colors do you want? Default is 1 for "primary" | 
| pattern | regular expression matching team names passed to 
 | 
| colors | A numeric vector of colors to return. Possible values are 
 | 
| ... | arguments passed to other functions | 
Details
Use league_pal to return a vector of colors for a spcefic
league.
Use team_pal to return a palette (named vector) of 
multiple colors for a specific team.
Value
For *_pal() functions, a named character vector of colors
For scale_*_teams() functions, a wrapper to 
scale_color_manual
or scale_fill_manual
See Also
teamcolors
Examples
league_pal("mlb", 2)
team_filter("New York")
team_vec("New York")
team_pal("Celtics")
team_pal("Lakers", 1:4)
team_pal("New York", 1:4)
if (require(Lahman) && require(dplyr) && require(ggplot2)) {
  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)) %>%
    left_join(teamcolors, by = "name")
    
  p <- 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_x_continuous("Winning Percentage", limits = c(0.3, 0.7)) + 
    scale_y_continuous("Expected Winning Percentage", limits = c(0.3, 0.7)) + 
    labs(title = "Real and Pythagorean winning % by team",
    subtitle = paste(pythag$yearID[1], "MLB Season", sep = " "),
    caption = "Source: the Lahman baseball database. Using teamcolors R pckg") +
    coord_equal()
    
  p +
    scale_fill_teams(name = "Team") + 
    scale_color_teams(name = "Team")
}
## Not run: 
show_team_col()
## End(Not run)
## Not run: 
show_ncaa_col()
## End(Not run)
Displays palettes for all teams for a specified sport
Description
Displays palettes for all teams for a specified sport
Usage
show_sport_col(sport, ...)
Arguments
| sport | character vector (basketball, soccer, football, hockey) | 
| ... | arguments passed to other functions | 
See Also
Examples
show_sport_col(sport = "soccer")
Color palettes for professional sports teams
Description
Color palettes for professional sports teams
Usage
teamcolors
Format
A data frame with one row for each professional team and five variables:
- name
- the name of the team as they are presented in the teamcolors dataset 
- league
- the league in which the team plays 
- primary
- the team's primary color 
- secondary
- the team's secondary color 
- tertiary
- the team's tertiary color 
- quaternary
- the team's quaternary color 
- division
- the team's division 
- location
- the team's location, not standardized 
- mascot
- the team's mascot 
- sportslogos_name
- the name of the team as they are presented on the sportslogos website 
- logo
- URL to the team's logo, hosted by http://www.sportslogos.net 
Details
The colors given are HTML hexidecimal values. See colors
for more information.
Source
http://jim-nielsen.com/teamcolors/, http://www.sportslogos.net, https://teamcolorcodes.com/
Examples
data(teamcolors)
if (require(Lahman) & require(dplyr)) {
  pythag <- Teams %>%
    filter(yearID == 2014) %>%
    select(name, W, L, R, RA) %>%
    mutate(wpct = W / (W+L), exp_wpct = 1 / (1 + (RA/R)^2)) %>%
    # St. Louis Cardinals do not match
    left_join(teamcolors, by = "name")
  with(pythag, plot(exp_wpct, wpct, bg = primary, col = secondary, pch = 21, cex = 3))
# Using ggplot2
if (require(ggplot2)) {
  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_manual(values = pythag$primary, guide = FALSE) + 
    scale_color_manual(values = pythag$secondary, guide = FALSE) + 
    geom_text(aes(label = substr(name, 1, 3))) + 
    scale_x_continuous("Winning Percentage", limits = c(0.3, 0.7)) + 
    scale_y_continuous("Expected Winning Percentage", limits = c(0.3, 0.7)) + 
    coord_equal()
  }
}