# \donttest{
library(mlbplotR)
library(ggplot2)
team_abbr <- valid_team_names()
# remove league logos from this example
team_abbr <- team_abbr[!team_abbr %in% c("AL", "NL", "MLB")]
df <- data.frame(
random_value = runif(length(team_abbr), 0, 1),
teams = team_abbr
)
# use logos for x-axis
ggplot(df, aes(x = teams, y = random_value)) +
geom_col(aes(color = teams, fill = teams), width = 0.5) +
scale_color_mlb(type = "secondary") +
scale_fill_mlb(alpha = 0.4) +
theme_minimal() +
theme(axis.text.x = element_mlb_logo())
# use logos for y-axis
ggplot(df, aes(y = teams, x = random_value)) +
geom_col(aes(color = teams, fill = teams), width = 0.5) +
scale_color_mlb(type = "secondary") +
scale_fill_mlb(alpha = 0.4) +
theme_minimal() +
theme(axis.text.y = element_mlb_logo())
#############################################################################
# Headshot Examples
#############################################################################
library(mlbplotR)
library(ggplot2)
dfh <- data.frame(
random_value = runif(9, 0, 1),
player_id = c("594798",
"592450",
"605141",
"665742",
"545361",
"665487",
"571448",
"0",
"543037")
)
# use headshots for x-axis
ggplot(dfh, aes(x = player_id, y = random_value)) +
geom_col(width = 0.5) +
theme_minimal() +
theme(axis.text.x = element_mlb_headshot())
# use headshots for y-axis
ggplot(dfh, aes(y = player_id, x = random_value)) +
geom_col(width = 0.5) +
theme_minimal() +
theme(axis.text.y = element_mlb_headshot())
# }
Run the code above in your browser using DataLab