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

plot_histogram(
  data,
  x_str = NULL,
  fill_str = NULL,
  fill = "#6FBBE3",
  bins = 12,
  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. If NULL, plot density using all values in data frame.

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.

bins

Number of histogram bins.

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_histogram()].

Value

A ggplot histogram.

See also

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

Examples

## plot distribution of all data in data frame
plot_histogram(as.data.frame(rnorm(1000), nrow = 100))

## plot distribution of a single column in data frame
plot_histogram(iris, x_str = "Sepal.Width")

plot_histogram(iris, x_str = "Sepal.Width", fill_str = "Species")