league_pal | R Documentation |
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(...)
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
show_col
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.