Wrapper around [ggplot2::geom_bar()] that plots pretty bar plots using a custom ggplot theme.

plot_bar(
  data,
  x_str,
  y_str = NULL,
  fill_str = NULL,
  fill = "#6FBBE3",
  stat = "count",
  position = "dodge",
  theme_options = NULL,
  show_plot = FALSE,
  ...
)

Arguments

data

Data frame to use for plot.

x_str

Character string. Name of variable in data to plot on x-axis.

y_str

Character string. Name of variable in data to plot on y-axis. Used only if stat = "identity".

fill_str

Character string (optional). Name of variable in data to use as fill aesthetic in plot.

fill

Fill color. Used only if fill_str is NULL.

stat

Override the default connection between geom_bar() and stat_count().

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

theme_options

(Optional) list of arguments to pass to vthemes::theme_vmodern().

show_plot

Logical. Should this plot be printed? Default FALSE.

...

Other arguments to pass to [ggplot2::geom_bar()].

Value

A ggplot bar plot.

See also

Other pretty_ggplot_wrappers: plot_boxplot(), plot_density(), plot_histogram(), plot_line(), plot_point()

Examples

df <- data.frame(x = rep(letters[1:3], 2), y = rep(LETTERS[1:2], 3))
plot_bar(data = df, x_str = "x")

plot_bar(df, x_str = "x", fill_str = "y")