R/MLB_Team_Graphic.R

Defines functions MLB_Team_Graphic

Documented in MLB_Team_Graphic

#' Create Histogram for MLB Team Batting Data for Shiny App
#'
#' @param TeamAbbr MLB Team Abbreviation
#' @param year MLB Season Year of Interest
#' @param statistic MLB Batting Statistic of Interest
#'
#' @return
#' @export
#'
#' @importFrom graphics hist
#' @importFrom stats na.omit
#' @examples
#' TeamAbbr <- 'CIN'
#' year <- 2021
#' statistic <- 'OBP'
#' CIN_2021_OBP <- MLB_Team_Graphic(TeamAbbr, year, statistic)
MLB_Team_Graphic <- function(TeamAbbr, year, statistic){
  data <- MLB_Team(TeamAbbr, year, 'B')
  stat <- as.data.frame(sapply(data[,c(statistic)], as.numeric))
  stat1 <- na.omit(stat)
  stat2 <- unlist(stat1)
  histogram <- hist(stat2, main= paste("Histogram for", TeamAbbr, statistic, "in", year), xlab= paste(statistic), breaks=10)
  return(histogram)
}
madeline-peyton/B581Final documentation built on Dec. 23, 2021, 11:16 p.m.