Skip to content

Team logos not fully showing  #15

@jacobakaye

Description

@jacobakaye
Screenshot 2024-02-05 at 11 47 10 PM

Here is the code:

# This part has been edited by @camdenk as a best estimation at what comes before this ----
# based on a previous gist
library(tidyverse)
library(baseballr)
library(gt)
library(gtExtras)
library(mlbplotR)

save_plot_local <- function(plot, plot_title, height, width) {
  ggsave(plot = plot, paste0("~/Desktop/mlbplotR_release/", plot_title, ".png"), 
         height = height, width = width, dpi = "retina")
}

theme_538 <- function() {
  ggthemes::theme_fivethirtyeight() +
    ggplot2::theme(
      plot.title = ggplot2::element_text(face = "bold"),
      axis.title.x = ggplot2::element_text(size = 12, face = "bold"),
      axis.title.y = ggplot2::element_text(size = 12, face = "bold"),
      legend.position = "right",
      legend.direction = "vertical"
    )
}


playoff_teams_2022 <- c("TB", "CLE", "NYY", "SEA", "TOR", "HOU", 
                        "ATL", "PHI", "STL", "LAD", "SDP", "NYM")
# End of Edited part ------------------------------------------------------------------------

team_hitting_2022 <- (fg_team_batter(startseason = 2022, endseason = 2022))
team_pitching_2022 <- (fg_team_pitcher(startseason = 2022, endseason = 2022))

team_hitting_2022

team_WAR_2022 <- team_hitting_2022 |> 
  select(team_name, hitting_WAR = WAR) |> 
  left_join(team_pitching_2022 |> select(team_name, pitching_WAR = WAR),
            by = "team_name") |> 
  mutate(team_name = clean_team_abbrs(team_name),
         playoff_team = team_name %in% playoff_teams_2022)


team_WAR_plot <- team_WAR_2022 |> 
  mutate(color = if_else(playoff_team, NA_character_, "b/w")) |> 
  ggplot(aes(hitting_WAR, pitching_WAR)) +
  geom_median_lines(aes(v_var = hitting_WAR, h_var = pitching_WAR)) +
  geom_mlb_logos(aes(team_abbr = team_name, color = color), width = 0.075, alpha = 0.75) +
  theme_538() + 
  scale_color_identity() +
  labs(title = "2022 MLB Teams by Hitting and Pitching WAR",
       subtitle = "Colored Logos Are Playoff Teams",
       caption = "Data: FanGraphs via baseballr",
       x = "Hitting WAR",
       y = "Pitching WAR")

save_plot_local(team_WAR_plot, "team_WAR", height = 8, width = 10)

team_WAR_plot

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions