Skip to contents

Enables the creation of barplots in a convenient and customizable manner, and calculates the associated Fisher's test p-value on the count data.

Usage

barplotter(
  data,
  x_val,
  y_val,
  order = NA,
  scale_labs = ggplot2::waiver(),
  pct = T,
  style = "light",
  colors = NA,
  y_lab = ggplot2::waiver(),
  x_lab = ggplot2::waiver(),
  title = "",
  labcol = "black",
  display_n = T,
  legend_lab = NA,
  labels = NA,
  filter_col = NA,
  filter_val = NA
)

Arguments

data

The data.frame to be used for the visualization.

x_val

string, the name of the column to plot on the x axis.

y_val

string, the name of the column to plot on the y axis.

order

vector, the order in which the bars should appear. It should include all unique values in x_val in the desired order. If unspecified, the bars follow the order of the dataframe.

scale_labs

vector, names to display on the x axis ticks. By default, it shows the names as they appear in x_val.

pct

boolean, if TRUE, percentages are displayed on the bars, if FALSE, the absolute numbers are shown.

style

string, palette style to be used for scale_fill_au. Default is light. Style is only applied if colors remains NA.

colors

vector containing the colors to be used for the fill aesthetic. Default is NA. If unspecified, the function uses au_colors().

y_lab

string, the y axis label. Default is percent. If pct = FALSE, the default is number.

x_lab

string, the x axis label. Default is the string passed into x_val.

title

string, the title of the plot to be displayed on top. Deafult is "".

labcol

string, the color of the annotation numbers displayed inside the bars. The default is black.

display_n

boolean, if TRUE, the plot displays the sample size appended to the title. Default is TRUE.

legend_lab

string, the legend title. Default is the string passed into y_val.

labels

vector, the legend annotations. Default is the unique values in y_val.

filter_col

string, the name of the column to filter data by. Default is NA.

filter_val

string or list, the entries to keep in filter_col. Default is NA.

Value

A ggplot object.

Examples

iris = dplyr::mutate(iris, Petal_mean = ifelse(Petal.Length > mean(Petal.Length),
"above_mean", "below_mean"))

barplotter(data = iris, x_val = "Species", y_val = "Petal_mean", labcol = "white")