R/fct_mod_contribution.R

Defines functions make_relplot

#' make plot for relative contributions
#' @importFrom dplyr select mutate arrange desc slice
#' @import plotly
#'
#' @noRd
make_relplot <- function(df, inps) {
  . <- Player <- NULL
  df2 <- df %>%
    select(Player, inps) %>%
    arrange(desc(.[[inps]])) %>%
    slice(1:7) %>%
    mutate(total = sum(.[inps])) %>%
    mutate(cont = as.vector(.[[inps]] / .$total))

  plt <- plot_ly(
    df2,
    labels = ~Player,
    values = df2[[inps]],
    text =  ~Player,
    type = "pie",
    hovertemplate = paste0("%{text}: <br>%{value} ", inps, "</br>")
  ) %>%
    layout(
      showlegend = FALSE
    )
  plt
}
nelstevens/baseballdashboard documentation built on May 25, 2023, 11:40 p.m.