R/utils_plot.R

Defines functions plot_dist

Documented in plot_dist

#' Plot Distribution as Histogram
#'
#' @param data (dataframe)
#' @param x (var) column from `data` to use as x-value
#' @param color (var) column from `color` to specify histogram color
#' @param n_obs (numeric) number of observations to use
#'
#' @return ggplot object
#' @export
plot_dist <- function(data, x = value, color = distribution, n_obs) {
  ggplot2::ggplot(data) +
    ggplot2::aes(x = {{x}},
                 color = {{color}},
                 fill = ggplot2::after_scale(ggplot2::alpha(color, 0.6))) +
    ggplot2::geom_histogram(bins = min(n_obs / 10, 100)) +
    cowplot::theme_cowplot()
}
JamesHWade/shinydist documentation built on March 29, 2022, 9:46 a.m.