Title: | Color Palettes for Pro Sports Teams |
---|---|
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. |
Authors: | Benjamin S. Baumer [aut, cre], Gregory J. Matthews [aut], Luke Benz [ctb], Arielle Dror [ctb], Clara Rosenberg [ctb], Paige Patrick [ctb], Allan Butler [ctb], Martin Lefebvre [ctb] |
Maintainer: | Benjamin S. Baumer <[email protected]> |
License: | GPL |
Version: | 0.0.4.9002 |
Built: | 2024-11-02 16:15:20 UTC |
Source: | https://github.com/beanumber/teamcolors |
Color palettes for sports teams
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(...)
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(...)
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 |
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.
For *_pal()
functions, a named character vector of colors
For scale_*_teams()
functions, a wrapper to
scale_color_manual
or scale_fill_manual
teamcolors
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)
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
show_sport_col(sport, ...)
show_sport_col(sport, ...)
sport |
character vector (basketball, soccer, football, hockey) |
... |
arguments passed to other functions |
show_sport_col(sport = "soccer")
show_sport_col(sport = "soccer")
Color palettes for professional sports teams
teamcolors
teamcolors
A data frame with one row for each professional team and five variables:
the name of the team as they are presented in the teamcolors dataset
the league in which the team plays
the team's primary color
the team's secondary color
the team's tertiary color
the team's quaternary color
the team's division
the team's location, not standardized
the team's mascot
the name of the team as they are presented on the sportslogos website
URL to the team's logo, hosted by http://www.sportslogos.net
The colors given are HTML hexidecimal values. See colors
for more information.
http://jim-nielsen.com/teamcolors/, http://www.sportslogos.net, https://teamcolorcodes.com/
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() } }
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() } }