R/home_run_contour.R

Defines functions home_run_contour

Documented in home_run_contour

home_run_contour <- function(df,
               L = seq(.04, .24, by = 0.04),
               title = "Probability of Home Run",
               NCOL = 2){

  if(is.data.frame(df) == TRUE) {
    df <- list(df)
    names(df) <- "Group"
  }
  N_df <- length(df)
  if(is.list(df) == TRUE){
    if(length(names(df)) == 0){
      names(df) <- paste("Group", 1:N_df)
    }
  }
  df_p <- NULL
  for(j in 1:N_df){
    df[[j]] %>%
      setup_inplay() %>%
      hr_h_gam_fit(HR = TRUE) %>%
      grid_predict() %>%
      mutate(Group = names(df)[j]) -> df_c
    df_p <- rbind(df_p, df_c)
  }

  if(N_df == 1){
    contour_graph(df_p, L, title)
  } else {
    contour_graph(df_p, L, title) +
      facet_wrap(~ Group, ncol = NCOL)
  }
}
bayesball/CalledStrike documentation built on April 29, 2024, 6:21 p.m.