R/get_bar_plot.R

Defines functions get_bar_plot

Documented in get_bar_plot

#' get_bar_plot
#'
#' generate bar plot
#'
#' @param df_1 dataframe
#' @param x variable for x-axis (qualitative variable)
#' @param y variable for y-axis (usually the frequency)
#' @param x_label x-axis label
#' @param y_label y-axis label
#'
#' @return plot
#' @export
#'
#' @examples
#' # VH frequency bar plot
#' data(bregs)
#' df_1 <- get_freq(bregs, vh)
#' get_bar_plot(df_1, vh, freq, "VH-gene", "Frequency (%)")
get_bar_plot <- function(df_1, x, y, x_label=NULL, y_label=NULL) {
  if (is.null(x_label))
    x_label <- enexpr(x)
  if (is.null(y_label))
    y_label <- enexpr(y)
  ggplot(df_1, aes(x=!!enexpr(x), y=!!enexpr(y))) +
    geom_bar(stat="identity") +
    my_theme() +
    xlab(x_label) +
    ylab(y_label)
}
thierrycnam/igfuns documentation built on May 4, 2020, 3:21 a.m.