league_pal: Color palettes for sports teams

Description Usage Arguments Details Value See Also Examples

View source: R/palettes.R

Description

Color palettes for sports teams

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15

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 filter

colors

A numeric vector of colors to return. Possible values are 1:4

...

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

show_col

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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)

teamcolors documentation built on Jan. 23, 2020, 1:06 a.m.