#' 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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.