R/col_plot.R

Defines functions col_plot

Documented in col_plot

#' @title FUNCTION_TITLE
#' @description FUNCTION_DESCRIPTION
#' @param tbl PARAM_DESCRIPTION
#' @param nest_id PARAM_DESCRIPTION
#' @param xmin PARAM_DESCRIPTION
#' @param xmax PARAM_DESCRIPTION
#' @param num_col PARAM_DESCRIPTION
#' @param tbl_measure PARAM_DESCRIPTION
#' @param tbl_id PARAM_DESCRIPTION
#' @param title_text PARAM_DESCRIPTION
#' @param xlab PARAM_DESCRIPTION
#' @return OUTPUT_DESCRIPTION
#' @details DETAILS
#' @examples
#' \dontrun{
#' if(interactive()){
#'  #EXAMPLE1
#'  }
#' }
#' @seealso
#'  \code{\link[scales]{label_number}}
#' @rdname col_plot
#' @export
#' @importFrom scales comma
#' @importFrom dplyr slice_max
#' @importFrom dplyr mutate
#' @importFrom forcats fct_reorder
#' @import ggplot2
col_plot <- function(tbl, nest_id, xmin, xmax, num_col, tbl_measure, tbl_id, title_text, xlab){
  tbl%>%
    slice_max(abs({{  tbl_measure  }}), n = num_col) %>%
    mutate(tbl_id = fct_reorder({{ tbl_id }},{{  tbl_measure  }} )) %>%
    ggplot(aes({{  tbl_measure  }}, tbl_id, fill = {{  tbl_measure  }} < 0)) +
    geom_col() +
    scale_x_continuous(labels = comma, limits=c(xmin,xmax)) +
    theme(legend.position = "none") +
    labs(title = paste(title_text, nest_id),
         x = xlab,
         y="")
}
rpmartin/maRtin documentation built on Jan. 21, 2022, 9:17 p.m.