bar_plot: bar_plot

View source: R/bar_plot.R

bar_plotR Documentation

bar_plot

Description

bar_plot

Usage

bar_plot(
  data,
  x,
  y = "1",
  group = NULL,
  facet_x = NULL,
  facet_y = NULL,
  size = 11,
  width = NULL,
  reorder = c("group", "facet_x", "facet_y"),
  palette = ez_col,
  labels_y = if (position == "fill") {
     function(x) ez_labels(100 * x, append =
    "%")
 } else {
     ez_labels
 },
  labels_x = identity,
  label_pos = c("auto", "inside", "top", "both", "none"),
  rescale_y = 1.1,
  label_cutoff = 0.12,
  use_theme = theme_ez,
  position = "stack",
  facet_scales = "fixed",
  legend_ncol = NULL,
  coord_flip = FALSE
)

Arguments

data

A data.frame.

x

A named character value. Evaluates to a column.

y

A named character value. Evaluates to a column.

group

A character value. Evaluates to a column.

facet_x

A character value. Evaluates to a column.

facet_y

A character. Evaluates to a column.

size

theme size for use_theme(). Default is 14.

width

Width of bar.

reorder

A character vector specifying the group variables to reorder. Default is c("group", "facet_x", "facet_y").

palette

Colour function.

labels_y

label formatting function

labels_x

label formatting function

label_pos

Position of labels. Can be "auto", "inside", "top", "both" or "none".

rescale_y

Rescaling factor for y-axis limits

label_cutoff

Cutoff size (proportion of y data range) for excluding labels

use_theme

ggplot theme function

position

Either "stack" (default) or "fill"

facet_scales

Option passed to scales argument in facet_wrap or facet_grid. Default is "fixed".

legend_ncol

Number of columns in legend.

coord_flip

logical (default is FALSE). If TRUE, flips the x and y coordinate using ggplot2::coord_flip()

Value

A ggplot object.

Examples

library(tsibble)
library(tsibbledata)
library(lubridate)
bar_plot(ansett, "year(Week)", "Passengers", size = 16)
bar_plot(ansett, "year(Week)", "Passengers", "Class")
bar_plot(ansett, "Airports", c("Share of Passengers" = "Passengers"), "Class", position = "fill")
bar_plot(ansett, "Airports", "Passengers", "Class", reorder = NULL, label_pos = "both")
bar_plot(ansett, "Airports",
         c(Passengers = "ifelse(Class == 'Economy', Passengers, -Passengers)"),
         "Class", label_pos = "both")
bar_plot(ansett, "year(Week)", "Passengers", "Class", label_pos = "both", coord_flip = TRUE)

ezplot documentation built on Aug. 12, 2022, 1:07 a.m.