R/facet_col_plot.R

Defines functions facet_col_plot

Documented in facet_col_plot

#' @title FUNCTION_TITLE
#' @description FUNCTION_DESCRIPTION
#' @param tbl PARAM_DESCRIPTION
#' @param nest_id PARAM_DESCRIPTION
#' @param yvar PARAM_DESCRIPTION
#' @param measure PARAM_DESCRIPTION
#' @param facet PARAM_DESCRIPTION
#' @return OUTPUT_DESCRIPTION
#' @details DETAILS
#' @examples
#' \dontrun{
#' if(interactive()){
#'  #EXAMPLE1
#'  }
#' }
#' @rdname facet_col_plot
#' @export
#' @importFrom scales comma
#' @importFrom dplyr slice_max
#' @importFrom dplyr mutate
#' @importFrom forcats fct_reorder
#' @import ggplot2
#' @importFrom tidytext reorder_within
#' @importFrom tidytext scale_y_reordered
facet_col_plot <- function(tbl, nest_id, yvar, measure, facet){
  tbl%>%
    mutate(yvar = reorder_within({{  yvar  }}, by= {{  measure  }}, within= {{  facet  }}))%>%
    ggplot(aes({{ measure  }}, yvar)) +
    geom_col() +
    scale_x_continuous() +
    scale_y_reordered() +
    facet_wrap(vars({{  facet  }}), scales = "free_y") +
    labs(y = "",
         title=nest_id)
}
rpmartin/maRtin documentation built on Jan. 21, 2022, 9:17 p.m.