Title: | Functions for Common Chart Types |
---|---|
Description: | Wrapper for the 'ggplot2' package that creates a variety of common charts (e.g. bar, line, area, ROC, waterfall, pie) while aiming to reduce typing. |
Authors: | Wojtek Kostelecki |
Maintainer: | Wojtek Kostelecki <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.8.1 |
Built: | 2024-11-20 05:22:49 UTC |
Source: | https://github.com/wkostelecki/ezplot |
Aggregates data
agg_data( data, cols = names(data), group_by = NULL, agg_fun = function(x) sum(x, na.rm = TRUE), group_by2 = NULL, env = parent.frame() )
agg_data( data, cols = names(data), group_by = NULL, agg_fun = function(x) sum(x, na.rm = TRUE), group_by2 = NULL, env = parent.frame() )
data |
A data.frame. |
cols |
Named character vector of column names. |
group_by |
Vector of grouping columns. |
agg_fun |
Function to use for aggregating. |
group_by2 |
Vector of grouping column names to use for delayed (post aggregation) calculation. |
env |
Environment for extra variables. |
An aggregated data.frame.
suppressPackageStartupMessages(library(tsibble)) library(tsibbledata) agg_data(ansett, c("Passengers", count = "1")) agg_data(ansett["Class"]) agg_data(ansett[c("Class", "Passengers")]) agg_data(ansett, "Passengers", "Class") agg_data(ansett, "Passengers", c("Class", "Airports")) agg_data(ansett, c(x = "Airports", y = "Passengers"), c(x = "Airports")) agg_data(ansett, c(x = "Class", y = "1", group = "Airports"), c(x = "Class", group = "Airports"))
suppressPackageStartupMessages(library(tsibble)) library(tsibbledata) agg_data(ansett, c("Passengers", count = "1")) agg_data(ansett["Class"]) agg_data(ansett[c("Class", "Passengers")]) agg_data(ansett, "Passengers", "Class") agg_data(ansett, "Passengers", c("Class", "Airports")) agg_data(ansett, c(x = "Airports", y = "Passengers"), c(x = "Airports")) agg_data(ansett, c(x = "Class", y = "1", group = "Airports"), c(x = "Class", group = "Airports"))
Aggregates a data.frame and creates a stacked area chart.
area_plot( data, x, y = "1", group = NULL, facet_x = NULL, facet_y = NULL, size = 11, 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 = NULL, use_theme = theme_ez, position = c("stack", "fill"), facet_scales = "fixed", facet_ncol = NULL, legend_ncol = NULL, env = parent.frame() )
area_plot( data, x, y = "1", group = NULL, facet_x = NULL, facet_y = NULL, size = 11, 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 = NULL, use_theme = theme_ez, position = c("stack", "fill"), facet_scales = "fixed", facet_ncol = NULL, legend_ncol = NULL, env = parent.frame() )
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 |
reorder |
A character vector specifying the group variables to reorder.
Default is |
palette |
Colour function. |
labels_y |
label formatting function |
labels_x |
label formatting function |
use_theme |
ggplot theme function |
position |
Either |
facet_scales |
Option passed to scales argument in |
facet_ncol |
Option passed to ncol argument in |
legend_ncol |
Number of columns in legend. |
env |
environment for evaluating expressions. |
A ggplot object.
library(tsibble) library(tsibbledata) area_plot(ansett, x = "as.Date(Week)", y = "Passengers") area_plot(ansett, x = "as.Date(Week)", y = c("Weekly Passengers" = "Passengers"), "Class") area_plot(ansett, "as.Date(Week)", y = c("Weekly Passengers" = "Passengers"), group = "substr(Airports, 5, 7)", facet_x = "substr(Airports, 1, 3)", facet_y = "Class", facet_scales = "free_y")
library(tsibble) library(tsibbledata) area_plot(ansett, x = "as.Date(Week)", y = "Passengers") area_plot(ansett, x = "as.Date(Week)", y = c("Weekly Passengers" = "Passengers"), "Class") area_plot(ansett, "as.Date(Week)", y = c("Weekly Passengers" = "Passengers"), group = "substr(Airports, 5, 7)", facet_x = "substr(Airports, 1, 3)", facet_y = "Class", facet_scales = "free_y")
bar_plot
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"), label_inside = c("y", "absolute", "share", "percent", "both"), rescale_y = 1.1, label_cutoff = 0.12, use_theme = theme_ez, position = "stack", facet_scales = "fixed", legend_ncol = NULL, coord_flip = FALSE, angle = 0, repel = FALSE )
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"), label_inside = c("y", "absolute", "share", "percent", "both"), rescale_y = 1.1, label_cutoff = 0.12, use_theme = theme_ez, position = "stack", facet_scales = "fixed", legend_ncol = NULL, coord_flip = FALSE, angle = 0, repel = FALSE )
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 |
width |
Width of bar. |
reorder |
A character vector specifying the group variables to reorder.
Default is |
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". |
label_inside |
Value to display inside bar segments. Options are "y", "absolute", "percent", "share" or "both". |
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 |
facet_scales |
Option passed to scales argument in |
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() |
angle |
angle for geom_text(_repel) |
repel |
logical (default if FALSE). If TRUE, uses ggrepel for geom_text |
A ggplot object.
library(tsibble) library(tsibbledata) library(lubridate) bar_plot(ansett, "year(Week)", "Passengers") bar_plot(ansett, "year(Week)", "Passengers", "Class", label_pos = "both") bar_plot(ansett, "year(Week)", "Passengers", "Class", label_pos = "both", label_inside = "both") bar_plot(ansett, "year(Week)", "Passengers", "Class", coord_flip = TRUE)
library(tsibble) library(tsibbledata) library(lubridate) bar_plot(ansett, "year(Week)", "Passengers") bar_plot(ansett, "year(Week)", "Passengers", "Class", label_pos = "both") bar_plot(ansett, "year(Week)", "Passengers", "Class", label_pos = "both", label_inside = "both") bar_plot(ansett, "year(Week)", "Passengers", "Class", coord_flip = TRUE)
calendar_plot
calendar_plot(data, x, y, ...)
calendar_plot(data, x, y, ...)
data |
A data.frame. |
x |
date column |
y |
A named character value. Evaluates to a column. |
... |
additional arguments for tile_plot |
library(tsibbledata) calendar_plot(vic_elec, "Time", "Demand", zlim = c(NA, NA))
library(tsibbledata) calendar_plot(vic_elec, "Time", "Demand", zlim = c(NA, NA))
creates a density plot
density_plot( data, x, group = NULL, facet_x = NULL, facet_y = NULL, palette = ez_col, adjust = 1, alpha = 0.5, facet_scales = "fixed", facet_ncol = NULL, legend_ncol = NULL, env = parent.frame() )
density_plot( data, x, group = NULL, facet_x = NULL, facet_y = NULL, palette = ez_col, adjust = 1, alpha = 0.5, facet_scales = "fixed", facet_ncol = NULL, legend_ncol = NULL, env = parent.frame() )
data |
A data.frame. |
x |
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. |
palette |
Colour function. |
adjust |
multiplicate bandwidth adjustment |
alpha |
alpha |
facet_scales |
Option passed to scales argument in |
facet_ncol |
Option passed to ncol argument in |
legend_ncol |
Number of columns in legend. |
env |
environment for evaluating expressions. |
library(tsibbledata) density_plot(mtcars, "wt", "cyl") density_plot(subset(tsibbledata::olympic_running, Length == 100 & Year >= 1980), "Time", "Year - Year %% 10", "Sex", facet_scales = "free", facet_ncol = 1, adjust = 2)
library(tsibbledata) density_plot(mtcars, "wt", "cyl") density_plot(subset(tsibbledata::olympic_running, Length == 100 & Year >= 1980), "Time", "Year - Year %% 10", "Sex", facet_scales = "free", facet_ncol = 1, adjust = 2)
distribution_plot
distribution_plot( data, x, facet_x = NULL, nbins = 20, use_theme = theme_ez, size = 11, env = parent.frame() )
distribution_plot( data, x, facet_x = NULL, nbins = 20, use_theme = theme_ez, size = 11, env = parent.frame() )
data |
A data.frame. |
x |
A named character value. Evaluates to a column. |
facet_x |
A character value. Evaluates to a column. |
nbins |
Number of bins for histogram. Default is 20. |
use_theme |
ggplot theme function |
size |
theme size for |
env |
environment for evaluating expressions. |
n = 100 df = data.frame(residuals = rnorm(n), group1 = sample(c("a", "b"), n, replace = TRUE)) distribution_plot(df, "residuals") distribution_plot(df, "residuals", "group1")
n = 100 df = data.frame(residuals = rnorm(n), group1 = sample(c("a", "b"), n, replace = TRUE)) distribution_plot(df, "residuals") distribution_plot(df, "residuals", "group1")
ez_app
ez_app(data = NULL)
ez_app(data = NULL)
data |
A data frame |
## Not run: library(tsibble) library(tsibbledata) ez_app(ansett) ## End(Not run)
## Not run: library(tsibble) library(tsibbledata) ez_app(ansett) ## End(Not run)
Color palette interpolation
ez_col(n = 50, palette = NULL)
ez_col(n = 50, palette = NULL)
n |
number of colours |
palette |
palette to interpolate from |
rgb
ez_col(15) ez_col(2, c("blue", "red")) ez_col(3, c("blue", "red"))
ez_col(15) ez_col(2, c("blue", "red")) ez_col(3, c("blue", "red"))
color palette for
ez_jet( n = 100, palette = c("dodgerblue4", "steelblue2", "olivedrab3", "darkgoldenrod1", "brown") )
ez_jet( n = 100, palette = c("dodgerblue4", "steelblue2", "olivedrab3", "darkgoldenrod1", "brown") )
n |
Number of colours to return. |
palette |
Vector of colours. |
ez_jet(100) ez_jet(1)
ez_jet(100) ez_jet(1)
Function for formatting numeric labels
ez_labels( x, prepend = "", append = "", as_factor = FALSE, round = Inf, signif = Inf, sign = FALSE )
ez_labels( x, prepend = "", append = "", as_factor = FALSE, round = Inf, signif = Inf, sign = FALSE )
x |
numeric |
prepend |
character |
append |
character |
as_factor |
logical |
round |
numeric passed to |
signif |
numeric passed to |
sign |
logical. Adds a plus sign to positive numbers |
y
ez_labels(10^(0:10)) ez_labels(2000, append = " apples") ez_labels(0:10, append = " apples", as_factor = TRUE) ez_labels(c(0, 0.1, 0.01, 0.001, 0.0001)) ez_labels(c(-1, -0.0001, 0, 0.0001, 1), round = 2, sign = FALSE) ez_labels(c(-1, -0.0001, 0, 0.0001, 1), round = 2, sign = TRUE)
ez_labels(10^(0:10)) ez_labels(2000, append = " apples") ez_labels(0:10, append = " apples", as_factor = TRUE) ez_labels(c(0, 0.1, 0.01, 0.001, 0.0001)) ez_labels(c(-1, -0.0001, 0, 0.0001, 1), round = 2, sign = FALSE) ez_labels(c(-1, -0.0001, 0, 0.0001, 1), round = 2, sign = TRUE)
Saves ggplot or ezplot objects to png (with useful defaults).
ez_png( g, file, width = 1200, height = 600, res = 72, resx = 1, ..., vp = NULL, dir.create = FALSE, check = TRUE )
ez_png( g, file, width = 1200, height = 600, res = 72, resx = 1, ..., vp = NULL, dir.create = FALSE, check = TRUE )
g |
A ggplot or ezplot object. |
file |
A png file path. |
width |
Image width (in pixels). Default is 1200. |
height |
Image height (in pixels). Default is 600. |
res |
Resolution (PPI) of output image. Default is 72. |
resx |
Resolution multiplier. Default is 1. |
... |
Further arguments to pass to |
vp |
A viewport object created with grid::viewport. |
dir.create |
Logical. If |
check |
Logical. If |
returns the minimum increment between sorted unique values of a vector
get_incr(x)
get_incr(x)
x |
A numeric or date vector |
creates a histogram plot
histogram_plot( data, x, y = "count", group = NULL, facet_x = NULL, facet_y = NULL, palette = ez_col, position = "stack", bins = 30, alpha = 0.5, facet_scales = "fixed", facet_ncol = NULL, legend_ncol = NULL, env = parent.frame() )
histogram_plot( data, x, y = "count", group = NULL, facet_x = NULL, facet_y = NULL, palette = ez_col, position = "stack", bins = 30, alpha = 0.5, facet_scales = "fixed", facet_ncol = NULL, legend_ncol = NULL, env = parent.frame() )
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. |
palette |
Colour function. |
position |
Either |
bins |
number of bins |
alpha |
fill alpha |
facet_scales |
Option passed to scales argument in |
facet_ncol |
Option passed to ncol argument in |
legend_ncol |
Number of columns in legend. |
env |
environment for evaluating expressions. |
histogram_plot(airquality, "Wind", group = "Month") histogram_plot(airquality, "Wind", "density", facet_x = "Month")
histogram_plot(airquality, "Wind", group = "Month") histogram_plot(airquality, "Wind", "density", facet_x = "Month")
ks plot
ks_plot( data, fitted, actual, palette = ez_col, size_line = 1, size = 11, env = parent.frame() )
ks_plot( data, fitted, actual, palette = ez_col, size_line = 1, size = 11, env = parent.frame() )
data |
A data.frame. |
fitted |
Vector of fitted values |
actual |
Vector of actual values |
palette |
Colour function. |
size_line |
width of line for |
size |
theme size for |
env |
environment for evaluating expressions. |
ks_plot(mtcars, "-disp", "am") x = c(rnorm(100), rnorm(100) + 2) label = c(rep('low', 100), rep('high', 100)) ks_plot(data.frame(x, label), "x", "label") ks_plot(data.frame(x, label = factor(label, c('low', 'high'))), "x", "label")
ks_plot(mtcars, "-disp", "am") x = c(rnorm(100), rnorm(100) + 2) label = c(rep('low', 100), rep('high', 100)) ks_plot(data.frame(x, label), "x", "label") ks_plot(data.frame(x, label = factor(label, c('low', 'high'))), "x", "label")
precision-recall plot
lift_plot( data, fitted, actual, group = NULL, facet_x = NULL, facet_y = NULL, size_line = 1, size = 11, env = parent.frame() )
lift_plot( data, fitted, actual, group = NULL, facet_x = NULL, facet_y = NULL, size_line = 1, size = 11, env = parent.frame() )
data |
A data.frame. |
fitted |
Vector of fitted values |
actual |
Vector of actual values |
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_line |
width of line for |
size |
theme size for |
env |
environment for evaluating expressions. |
library(ggplot2) n = 1000 df = data.frame(actual = sample(c(FALSE, TRUE), n, replace = TRUE), runif = runif(n)) df[["fitted"]] = runif(n) ^ ifelse(df[["actual"]] == 1, 0.5, 2) density_plot(df, "fitted", "actual") lift_plot(df, "fitted", "actual") lift_plot(df, "fitted", "actual") + scale_y_log10() lift_plot(df, "runif", "actual", size_line = 0.5) library(dplyr, warn.conflicts = FALSE) lift_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)") lift_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)", "sample(c(3, 4), n(), TRUE)") lift_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)", "sample(c(3, 4), n(), TRUE)", "sample(c(5, 6), n(), TRUE)")
library(ggplot2) n = 1000 df = data.frame(actual = sample(c(FALSE, TRUE), n, replace = TRUE), runif = runif(n)) df[["fitted"]] = runif(n) ^ ifelse(df[["actual"]] == 1, 0.5, 2) density_plot(df, "fitted", "actual") lift_plot(df, "fitted", "actual") lift_plot(df, "fitted", "actual") + scale_y_log10() lift_plot(df, "runif", "actual", size_line = 0.5) library(dplyr, warn.conflicts = FALSE) lift_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)") lift_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)", "sample(c(3, 4), n(), TRUE)") lift_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)", "sample(c(3, 4), n(), TRUE)", "sample(c(5, 6), n(), TRUE)")
Creates line plots.
line_plot( data, x, y = "1", group = NULL, facet_x = NULL, facet_y = NULL, yoy = FALSE, size_line = 1, points = FALSE, size = 11, reorder = c("group", "facet_x", "facet_y"), palette = ez_col, labels_y = ez_labels, limits_y = c(NA, NA), use_theme = theme_ez, facet_scales = "fixed", na.rm = FALSE, legend_ncol = NULL )
line_plot( data, x, y = "1", group = NULL, facet_x = NULL, facet_y = NULL, yoy = FALSE, size_line = 1, points = FALSE, size = 11, reorder = c("group", "facet_x", "facet_y"), palette = ez_col, labels_y = ez_labels, limits_y = c(NA, NA), use_theme = theme_ez, facet_scales = "fixed", na.rm = FALSE, legend_ncol = NULL )
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. |
yoy |
Logical used to indicate whether a YOY grouping should be created.
Default is |
size_line |
width of line for |
points |
logical. Option to include points |
size |
theme size for |
reorder |
A character vector specifying the group variables to reorder.
Default is |
palette |
Colour function. |
labels_y |
label formatting function |
limits_y |
vector of c(min, max) y-axis limits |
use_theme |
ggplot theme function |
facet_scales |
Option passed to scales argument in |
na.rm |
logical. Option to exclude NAs |
legend_ncol |
Number of columns in legend. |
A ggplot object.
suppressPackageStartupMessages(library(tsibble)) library(tsibbledata) line_plot(pelt, "Year", c("Hare", "Lynx"), points = TRUE, limits_y = c(0, NA))
suppressPackageStartupMessages(library(tsibble)) library(tsibbledata) line_plot(pelt, "Year", c("Hare", "Lynx"), points = TRUE, limits_y = c(0, NA))
model_plot
model_plot( data, x, actual, fitted, facet_x = NULL, point_size = 2, res_bins = NA_real_, size = 11 )
model_plot( data, x, actual, fitted, facet_x = NULL, point_size = 2, res_bins = NA_real_, size = 11 )
data |
A data.frame. |
x |
A named character value. Evaluates to a column. |
actual |
A character value. Evaluates to a logical or binary column. |
fitted |
A character value. Evaluates to a numeric column. |
facet_x |
A character value. Evaluates to a column. |
point_size |
Numeric. Default is 2. |
res_bins |
Number of bins in the residual distribution. Default value (NA) doesn't show the distribution. |
size |
theme size for |
A ggplot object.
y = rnorm(26) df = data.frame(ID = 1:26, actual = y + rnorm(26), fitted = y, id = letters) model_plot(df, "ID", "actual", "fitted") model_plot(df, "id", "actual", "fitted") model_plot(df, "ID", "actual", "fitted", res_bins = 10) model_plot(df, "id", "actual", "fitted", res_bins = 10)
y = rnorm(26) df = data.frame(ID = 1:26, actual = y + rnorm(26), fitted = y, id = letters) model_plot(df, "ID", "actual", "fitted") model_plot(df, "id", "actual", "fitted") model_plot(df, "ID", "actual", "fitted", res_bins = 10) model_plot(df, "id", "actual", "fitted", res_bins = 10)
Visual representation of the NAs in a data.frame
na_plot(data, palette = ez_col)
na_plot(data, palette = ez_col)
data |
A data.frame. |
palette |
Colour function. |
A ggplot object.
na_plot(airquality)
na_plot(airquality)
Names unnamed elements of a character vector.
nameifnot(x, make.names = FALSE)
nameifnot(x, make.names = FALSE)
x |
A character vector. |
make.names |
Logical. Whether to force names of x to be valid variable names. Default is FALSE. |
A named vector.
Converts "NULL" character to NULL.
no_null(x)
no_null(x)
x |
A character vector. |
y
no_null(NULL) no_null("NULL") no_null("NOPE")
no_null(NULL) no_null("NULL") no_null("NOPE")
Returns names of non-numeric columns.
not_numeric(x)
not_numeric(x)
x |
A data.frame. |
A character vector.
Precision recall calculation
perf(fitted, actual, x_measure, y_measure)
perf(fitted, actual, x_measure, y_measure)
fitted |
Vector with values between 0 and 1 |
actual |
Vector with two levels |
x_measure |
metric for ROCR::performance |
y_measure |
metric for ROCR::performance |
ezplot:::perf(runif(1), sample(c(TRUE, FALSE), 1, replace = TRUE), "rpp", "lift") ezplot:::perf(runif(10), sample(c(TRUE, FALSE), 10, replace = TRUE), "rpp", "lift") ezplot:::perf(runif(5), sample(c(TRUE, FALSE), 5, replace = TRUE), "rec", "prec") ezplot:::perf(runif(5), sample(c(TRUE, FALSE), 5, replace = TRUE), "fpr", "tpr") ezplot:::perf(runif(5), sample(c(TRUE, FALSE), 5, replace = TRUE), "cutoff", "tpr")
ezplot:::perf(runif(1), sample(c(TRUE, FALSE), 1, replace = TRUE), "rpp", "lift") ezplot:::perf(runif(10), sample(c(TRUE, FALSE), 10, replace = TRUE), "rpp", "lift") ezplot:::perf(runif(5), sample(c(TRUE, FALSE), 5, replace = TRUE), "rec", "prec") ezplot:::perf(runif(5), sample(c(TRUE, FALSE), 5, replace = TRUE), "fpr", "tpr") ezplot:::perf(runif(5), sample(c(TRUE, FALSE), 5, replace = TRUE), "cutoff", "tpr")
shows classification performance statistics as a table
perf_df(fitted, actual, quantiles = NULL)
perf_df(fitted, actual, quantiles = NULL)
fitted |
A character value. Evaluates to a numeric column. |
actual |
A character value. Evaluates to a logical or binary column. |
quantiles |
Number of quantiles to show. If |
A data.frame summarizing binary classification performance:
quantile: fitted value quantile (only if !is.null(quantile)
cutoff: fitted value cutoff
fp: false positives
tp: true positives
tn: true negatives
fn: false negatives
pp: positive predictions
np: negative predictions
ipp: group positive predictions
ifp: group false positives
itp: group true positives
rpp: rate of positive predictions
acc: accuracy
fpr: false positive rate
tpr: true positive rate
fnr: false negative rate
tnr: true negative rate
prec: precision
clift: lift
ilift: group lift
f1: f1 measure
ks: Kolmogorov-Smirnov statistic
auc: area under ROC curve
aucpr: area under PR curve
perf_df(mtcars$mpg, mtcars$am) perf_df(mtcars$mpg, mtcars$am, quantiles = 4) perf_df(mtcars$mpg, mtcars$am, quantiles = 8) perf_df(mtcars$mpg, mtcars$am, quantiles = 10) perf_df(mtcars$wt, mtcars$am==0)
perf_df(mtcars$mpg, mtcars$am) perf_df(mtcars$mpg, mtcars$am, quantiles = 4) perf_df(mtcars$mpg, mtcars$am, quantiles = 8) perf_df(mtcars$mpg, mtcars$am, quantiles = 10) perf_df(mtcars$wt, mtcars$am==0)
plots binary classification performance metrics
performance_plot( data, fitted, actual, group = NULL, facet_x = NULL, facet_y = NULL, x = "fpr", y = "tpr", auc = c("title", "group"), size_line = 1, size = 11, env = parent.frame() )
performance_plot( data, fitted, actual, group = NULL, facet_x = NULL, facet_y = NULL, x = "fpr", y = "tpr", auc = c("title", "group"), size_line = 1, size = 11, env = parent.frame() )
data |
A data.frame. |
fitted |
A character value. Evaluates to a numeric column. |
actual |
A character value. Evaluates to a logical or binary 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. |
x |
ROCR::performance() measure |
y |
ROCR::performance() measure |
auc |
character vector indicating which AUC values should be displayed. Options are 'title' and 'group' |
size_line |
width of line for |
size |
theme size for |
env |
environment for evaluating expressions. |
performance_plot(mtcars, "-disp", "am") performance_plot(mtcars, "-disp", "am", "cyl") performance_plot(mtcars, "-disp", "am", "cyl", x = "rec", y = "prec") performance_plot(mtcars, "-disp", "am", x = "rpp", y = "gain") performance_plot(mtcars, "-disp", "am", x = "rpp", y = "lift") performance_plot(mtcars, "-disp", "am", x = "cutoff", y = "tpr")
performance_plot(mtcars, "-disp", "am") performance_plot(mtcars, "-disp", "am", "cyl") performance_plot(mtcars, "-disp", "am", "cyl", x = "rec", y = "prec") performance_plot(mtcars, "-disp", "am", x = "rpp", y = "gain") performance_plot(mtcars, "-disp", "am", x = "rpp", y = "lift") performance_plot(mtcars, "-disp", "am", x = "cutoff", y = "tpr")
Creates pie charts.
pie_plot( data, x, y = "1", facet_x = NULL, facet_y = NULL, labels_y = function(x) ez_labels(x * 100, append = "%", round = round, signif = signif), size = 11, label_cutoff = 0.04, round = Inf, signif = 3, palette = ez_col, reorder = c("x", "facet_x", "facet_y"), label_x = 0.8, legend_ncol = NULL )
pie_plot( data, x, y = "1", facet_x = NULL, facet_y = NULL, labels_y = function(x) ez_labels(x * 100, append = "%", round = round, signif = signif), size = 11, label_cutoff = 0.04, round = Inf, signif = 3, palette = ez_col, reorder = c("x", "facet_x", "facet_y"), label_x = 0.8, legend_ncol = NULL )
data |
A data.frame. |
x |
A named character value. Evaluates to a column. |
y |
A named character value. Evaluates to a column. |
facet_x |
A character value. Evaluates to a column. |
facet_y |
A character. Evaluates to a column. |
labels_y |
label formatting function |
size |
theme size for |
label_cutoff |
Cutoff size (proportion of y data range) for excluding labels |
round |
Option for rounding label. |
signif |
Option for retaining significant figures in label. |
palette |
Colour function. |
reorder |
A character vector specifying the group variables to reorder.
Default is |
label_x |
Position of label from centre of pie. 0 is the centre of the pie and 1 is the outer edge. |
legend_ncol |
Number of columns in legend. |
ggplot object
suppressPackageStartupMessages(library(tsibble)) library(tsibbledata) pie_plot(ansett, "Class", "Passengers") pie_plot(ansett, "Class", "Passengers", reorder = NULL, label_x = 0.5) pie_plot(ansett, "Class", "Passengers", "Airports", reorder = NULL, label_x = 0.5)
suppressPackageStartupMessages(library(tsibble)) library(tsibbledata) pie_plot(ansett, "Class", "Passengers") pie_plot(ansett, "Class", "Passengers", reorder = NULL, label_x = 0.5) pie_plot(ansett, "Class", "Passengers", "Airports", reorder = NULL, label_x = 0.5)
precision-recall plot
pr_plot( data, fitted, actual, group = NULL, facet_x = NULL, facet_y = NULL, palette = ez_col, size_line = 1, size = 11, labs = "short", env = parent.frame() )
pr_plot( data, fitted, actual, group = NULL, facet_x = NULL, facet_y = NULL, palette = ez_col, size_line = 1, size = 11, labs = "short", env = parent.frame() )
data |
A data.frame. |
fitted |
Vector of fitted values |
actual |
Vector of actual values |
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. |
palette |
Colour function. |
size_line |
width of line for |
size |
theme size for |
labs |
'short' or 'long' |
env |
environment for evaluating expressions. |
library(ggplot2) n = 1000 df = data.frame(actual = sample(c(FALSE, TRUE), n, replace = TRUE), runif = runif(n)) df[["fitted"]] = runif(n) ^ ifelse(df[["actual"]] == 1, 0.5, 2) density_plot(df, "fitted", "actual") pr_plot(df, "fitted", "actual") pr_plot(df, "runif", "actual", size_line = 0.5) library(dplyr, warn.conflicts = FALSE) pr_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)") pr_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)", "sample(c(3, 4), n(), TRUE)") pr_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)", "sample(c(3, 4), n(), TRUE)", "sample(c(5, 6), n(), TRUE)")
library(ggplot2) n = 1000 df = data.frame(actual = sample(c(FALSE, TRUE), n, replace = TRUE), runif = runif(n)) df[["fitted"]] = runif(n) ^ ifelse(df[["actual"]] == 1, 0.5, 2) density_plot(df, "fitted", "actual") pr_plot(df, "fitted", "actual") pr_plot(df, "runif", "actual", size_line = 0.5) library(dplyr, warn.conflicts = FALSE) pr_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)") pr_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)", "sample(c(3, 4), n(), TRUE)") pr_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)", "sample(c(3, 4), n(), TRUE)", "sample(c(5, 6), n(), TRUE)")
Precision recall calculation
prec_rec(fitted, actual)
prec_rec(fitted, actual)
fitted |
Vector with values between 0 and 1 |
actual |
Vector with two levels |
ezplot:::prec_rec(runif(1), sample(c(TRUE, FALSE), 1, replace = TRUE)) ezplot:::prec_rec(runif(5), sample(c(TRUE, FALSE), 5, replace = TRUE))
ezplot:::prec_rec(runif(1), sample(c(TRUE, FALSE), 1, replace = TRUE)) ezplot:::prec_rec(runif(5), sample(c(TRUE, FALSE), 5, replace = TRUE))
Applies faceting to ggplot objects when g[["data"]] has a
facet_x
or facet_y
column.
quick_facet(g, ncol = NULL, ...)
quick_facet(g, ncol = NULL, ...)
g |
A ggplot object. |
ncol |
Number of facet columns. |
... |
Arguments to pass to |
Order levels of factor columns using fct_reorder
reorder_levels( data, cols = c("group", "facet_x", "facet_y"), y = "y", .desc = rep(TRUE, length(cols)) )
reorder_levels( data, cols = c("group", "facet_x", "facet_y"), y = "y", .desc = rep(TRUE, length(cols)) )
data |
A data.frame. |
cols |
Names of columns to reorder. |
y |
Numeric column for order priority. |
.desc |
A logical vector of length 1 or ncol(data). Default is TRUE for
all columns in |
A data.frame.
str(ezplot:::reorder_levels(mtcars, "cyl", "1")) str(ezplot:::reorder_levels(mtcars, "cyl", "1", FALSE)) str(ezplot:::reorder_levels(mtcars, "cyl", "mpg"))
str(ezplot:::reorder_levels(mtcars, "cyl", "1")) str(ezplot:::reorder_levels(mtcars, "cyl", "1", FALSE)) str(ezplot:::reorder_levels(mtcars, "cyl", "mpg"))
Calculates ROC and AUC
roc(fitted, actual)
roc(fitted, actual)
fitted |
Vector with values between 0 and 1 |
actual |
Vector with two levels |
ezplot:::roc(runif(1), sample(c(TRUE, FALSE), 1, replace = TRUE)) ezplot:::roc(runif(3), sample(c(TRUE, FALSE), 3, replace = TRUE))
ezplot:::roc(runif(1), sample(c(TRUE, FALSE), 1, replace = TRUE)) ezplot:::roc(runif(3), sample(c(TRUE, FALSE), 3, replace = TRUE))
roc_plot
roc_plot( data, fitted, actual, group = NULL, facet_x = NULL, facet_y = NULL, palette = ez_col, size_line = 1, size = 11, env = parent.frame() )
roc_plot( data, fitted, actual, group = NULL, facet_x = NULL, facet_y = NULL, palette = ez_col, size_line = 1, size = 11, env = parent.frame() )
data |
A data.frame. |
fitted |
Vector of fitted values |
actual |
Vector of actual values |
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. |
palette |
Colour function. |
size_line |
width of line for |
size |
theme size for |
env |
environment for evaluating expressions. |
library(ggplot2) n = 1000 df = data.frame(actual = sample(c(FALSE, TRUE), n, replace = TRUE), runif = runif(n)) df[["fitted"]] = runif(n) ^ ifelse(df[["actual"]] == 1, 0.5, 2) ggplot(df) + geom_density(aes(fitted, fill = actual), alpha = 0.5) roc_plot(df, "actual", "actual") roc_plot(df, "fitted", "actual") roc_plot(df, "runif", "actual", size_line = 0.5) library(dplyr, warn.conflicts = FALSE) roc_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)") roc_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)", "sample(c(3, 4), n(), TRUE)") roc_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)", "sample(c(3, 4), n(), TRUE)", "sample(c(5, 6), n(), TRUE)")
library(ggplot2) n = 1000 df = data.frame(actual = sample(c(FALSE, TRUE), n, replace = TRUE), runif = runif(n)) df[["fitted"]] = runif(n) ^ ifelse(df[["actual"]] == 1, 0.5, 2) ggplot(df) + geom_density(aes(fitted, fill = actual), alpha = 0.5) roc_plot(df, "actual", "actual") roc_plot(df, "fitted", "actual") roc_plot(df, "runif", "actual", size_line = 0.5) library(dplyr, warn.conflicts = FALSE) roc_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)") roc_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)", "sample(c(3, 4), n(), TRUE)") roc_plot(df, "fitted", "actual", "sample(c(1, 2), n(), TRUE)", "sample(c(3, 4), n(), TRUE)", "sample(c(5, 6), n(), TRUE)")
Saves ggplot or ezplot objects to png.
save_png(g, file, width, height, res, ..., vp = NULL)
save_png(g, file, width, height, res, ..., vp = NULL)
g |
A ggplot or ezplot object. |
file |
A png file path. |
width |
Width of output image. |
height |
Height or output image. |
res |
Resolution of output image. |
... |
Further arguments to pass to |
vp |
A viewport object created with grid::viewport. |
create a scatter plot
scatter_plot( data, x, y, group = NULL, palette = ez_col, size = 11, point_size = 2.5, smooth = FALSE, env = parent.frame() )
scatter_plot( data, x, y, group = NULL, palette = ez_col, size = 11, point_size = 2.5, smooth = FALSE, env = parent.frame() )
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. |
palette |
Colour function. |
size |
theme size for |
point_size |
Numeric. Default is 2. |
smooth |
logical. If |
env |
environment for evaluating expressions. |
scatter_plot(mtcars, "wt", "hp") scatter_plot(mtcars, "wt", "hp", "factor(cyl)") scatter_plot(mtcars, "factor(cyl)", "hp")
scatter_plot(mtcars, "wt", "hp") scatter_plot(mtcars, "wt", "hp", "factor(cyl)") scatter_plot(mtcars, "factor(cyl)", "hp")
secondary_plot creates a plot with a secondary y-axis
secondary_plot( data, x, y1 = "1", y2 = "1", facet_x = NULL, facet_y = NULL, palette = ez_col, size_line = 1, labels_y1 = ez_labels, labels_y2 = ez_labels, ylim1 = NULL, ylim2 = NULL, reorder = c("facet_x", "facet_y"), size = 11 )
secondary_plot( data, x, y1 = "1", y2 = "1", facet_x = NULL, facet_y = NULL, palette = ez_col, size_line = 1, labels_y1 = ez_labels, labels_y2 = ez_labels, ylim1 = NULL, ylim2 = NULL, reorder = c("facet_x", "facet_y"), size = 11 )
data |
A data.frame. |
x |
A named character value. Evaluates to a column. |
y1 |
Variable to plot on the left-hand axis |
y2 |
Variable to plot on the right-hand axis |
facet_x |
A character value. Evaluates to a column. |
facet_y |
A character. Evaluates to a column. |
palette |
Colour function. |
size_line |
line size |
labels_y1 |
label formatting function |
labels_y2 |
label formatting function |
ylim1 |
(optional) left axis limits |
ylim2 |
(optional) right axis limits |
reorder |
A character vector specifying the group variables to reorder.
Default is |
size |
theme size for |
A ggplot object.
suppressPackageStartupMessages(library(tsibble)) library(tsibbledata) secondary_plot(pelt, "Year", "Hare", "Lynx") secondary_plot(pelt, "Year", c("Hare Population" = "Hare"), c("Lynx Population" = "Lynx")) secondary_plot(aus_production, "Quarter", c("Quarterly Beer Production (megalitres)" = "Beer"), c("Quarterly Cement Production (tonnes)" = "Cement"), "lubridate::quarter(Quarter)", ylim1 = c(0, 600), ylim2 = c(0, 3000), size = 10)
suppressPackageStartupMessages(library(tsibble)) library(tsibbledata) secondary_plot(pelt, "Year", "Hare", "Lynx") secondary_plot(pelt, "Year", c("Hare Population" = "Hare"), c("Lynx Population" = "Lynx")) secondary_plot(aus_production, "Quarter", c("Quarterly Beer Production (megalitres)" = "Beer"), c("Quarterly Cement Production (tonnes)" = "Cement"), "lubridate::quarter(Quarter)", ylim1 = c(0, 600), ylim2 = c(0, 3000), size = 10)
side_plot
side_plot( data, x, y = "1", labels_y = ez_labels, size = 11, palette = ez_col, signif = 3, reorder = TRUE, rescale_y = 1.25 )
side_plot( data, x, y = "1", labels_y = ez_labels, size = 11, palette = ez_col, signif = 3, reorder = TRUE, rescale_y = 1.25 )
data |
A data.frame. |
x |
A named character value. Evaluates to a column. |
y |
A named character value. Evaluates to a column. |
labels_y |
label formatting function |
size |
theme size for |
palette |
Colour function. |
signif |
Number of significant digits. |
reorder |
A character vector specifying the group variables to reorder.
Default is |
rescale_y |
Rescaling factor for y-axis limits |
side_plot(mtcars, "gear", "1", rescale_y = 4/3) side_plot(mtcars, "cyl", c("Cars with <120 HP" = "hp < 120")) side_plot(mtcars, "cyl", c(count = "ifelse(cyl == 4, 1, -1)", "hp <= 120")) side_plot(mtcars, "cyl", c("hp <= 120", "~ - wt / cyl"), rescale_y = 1.5) side_plot(mtcars, "cyl", c("1", "-1"))
side_plot(mtcars, "gear", "1", rescale_y = 4/3) side_plot(mtcars, "cyl", c("Cars with <120 HP" = "hp < 120")) side_plot(mtcars, "cyl", c(count = "ifelse(cyl == 4, 1, -1)", "hp <= 120")) side_plot(mtcars, "cyl", c("hp <= 120", "~ - wt / cyl"), rescale_y = 1.5) side_plot(mtcars, "cyl", c("1", "-1"))
text_contrast
text_contrast(x)
text_contrast(x)
x |
Vector of colours. |
Vector indicating whether black or white should be used for text overlayed on x.
text_contrast("#000000") text_contrast("black")
text_contrast("#000000") text_contrast("black")
Default theme
theme_ez(base_size = 11, base_family = "")
theme_ez(base_size = 11, base_family = "")
base_size |
base font size |
base_family |
base fond family |
theme
library(ggplot2) ggplot(mtcars) + geom_point(aes(cyl, mpg)) + theme_ez()
library(ggplot2) ggplot(mtcars) + geom_point(aes(cyl, mpg)) + theme_ez()
Creates tile plots.
tile_plot( data, x, y, z = c(Count = "1"), facet_x = NULL, facet_y = NULL, size = 11, facet_ncol = NULL, labels_x = NULL, labels_y = NULL, labels_z = ez_labels, zlim = function(x) c(pmin(0, x[1]), pmax(0, x[2])), palette = ez_jet, reorder = c("facet_x", "facet_y") )
tile_plot( data, x, y, z = c(Count = "1"), facet_x = NULL, facet_y = NULL, size = 11, facet_ncol = NULL, labels_x = NULL, labels_y = NULL, labels_z = ez_labels, zlim = function(x) c(pmin(0, x[1]), pmax(0, x[2])), palette = ez_jet, reorder = c("facet_x", "facet_y") )
data |
A data.frame. |
x |
A named character value. Evaluates to a column. |
y |
A named character value. Evaluates to a column. |
z |
A named character. Evaluates to a column and is mapped to the fill colour of the tiles. |
facet_x |
A character value. Evaluates to a column. |
facet_y |
A character. Evaluates to a column. |
size |
theme size for |
facet_ncol |
Option passed to ncol argument in |
labels_x |
label formatting function |
labels_y |
label formatting function |
labels_z |
label formatting function |
zlim |
argument for |
palette |
Colour function. |
reorder |
A character vector specifying the group variables to reorder.
Default is |
## Not run: library(tsibbledata) library(dplyr) nyc_bikes %>% mutate(duration = as.numeric(stop_time - start_time)) %>% filter(between(duration, 0, 16)) %>% tile_plot(c("Hour of Day" = "lubridate::hour(start_time) + 0.5"), c("Ride Duration (min)" = "duration - duration %% 2 + 1")) ## End(Not run)
## Not run: library(tsibbledata) library(dplyr) nyc_bikes %>% mutate(duration = as.numeric(stop_time - start_time)) %>% filter(between(duration, 0, 16)) %>% tile_plot(c("Hour of Day" = "lubridate::hour(start_time) + 0.5"), c("Ride Duration (min)" = "duration - duration %% 2 + 1")) ## End(Not run)
Unpack cols argument to agg_data
unpack_cols(x)
unpack_cols(x)
x |
cols |
list
ezplot:::unpack_cols("x") ezplot:::unpack_cols(c(x = "x", y = "x + y", expr = "~ x + y"))
ezplot:::unpack_cols("x") ezplot:::unpack_cols(c(x = "x", y = "x + y", expr = "~ x + y"))
Plots variables (multiple "y" values) broken out as vertical facets.
variable_plot( data, x, y, group = NULL, facet_x = NULL, palette = ez_col, size = 14, labels_y = ez_labels, geom = "line", size_line = 1, legend_ncol = NULL, ylab = NULL, yoy = FALSE, switch = "y", rescale_y = 1 )
variable_plot( data, x, y, group = NULL, facet_x = NULL, palette = ez_col, size = 14, labels_y = ez_labels, geom = "line", size_line = 1, legend_ncol = NULL, ylab = NULL, yoy = FALSE, switch = "y", rescale_y = 1 )
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. |
palette |
Colour function. |
size |
theme size for |
labels_y |
label formatting function |
geom |
Either "line", "col" or "bar". Default is "line" |
size_line |
width of line for |
legend_ncol |
Number of columns in legend. |
ylab |
y label text |
yoy |
Logical used to indicate whether a YOY grouping should be created.
Default is |
switch |
Option to switch location of variable (facet) labels. Default is 'y' (yes) which shows facet strips on left side of panels. |
rescale_y |
Rescaling factor for y-axis limits |
suppressPackageStartupMessages(library(tsibble)) library(tsibbledata) variable_plot(ansett, "Week", "Passengers", facet_x = "Class", yoy = TRUE) variable_plot(pelt, "Year", c("Lynx", "Hare"), "round(Year, -1)")
suppressPackageStartupMessages(library(tsibble)) library(tsibbledata) variable_plot(ansett, "Week", "Passengers", facet_x = "Class", yoy = TRUE) variable_plot(pelt, "Year", c("Lynx", "Hare"), "round(Year, -1)")
function for creating waterfall charts
waterfall_plot( data, x, y, group, size = 11, labels = ez_labels, label_rescale = 1, y_min = "auto", rescale_y = 1.1, n_signif = 3, rotate_xlabel = FALSE, bottom_label = TRUE, ingroup_label = FALSE, n_x = 2, env = parent.frame() )
waterfall_plot( data, x, y, group, size = 11, labels = ez_labels, label_rescale = 1, y_min = "auto", rescale_y = 1.1, n_signif = 3, rotate_xlabel = FALSE, bottom_label = TRUE, ingroup_label = FALSE, n_x = 2, env = parent.frame() )
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. |
size |
theme size for |
labels |
Function for formatting labels. |
label_rescale |
Scaling factor for chart labels (relative to axis labels). |
y_min |
Minimum limit of y axis. |
rescale_y |
Rescaling factor for y-axis limits |
n_signif |
Number of significant figures in labels. |
rotate_xlabel |
Logical. |
bottom_label |
Logical. |
ingroup_label |
Logical. Shows in-group percentage change. |
n_x |
Number of x levels to show in chart. |
env |
environment for evaluating expressions. |
library(tsibbledata) waterfall_plot(aus_retail, "lubridate::year(Month)", "Turnover", "sub(' Territory', '\nTerritory', State)", rotate_xlabel = TRUE) waterfall_plot(aus_retail, "lubridate::year(Month)", "Turnover", "sub(' Territory', '\nTerritory', State)", rotate_xlabel = TRUE, label_rescale = 0.5, ingroup_label = TRUE, bottom_label = FALSE, n_x = 3, size = 20, y_min = 0)
library(tsibbledata) waterfall_plot(aus_retail, "lubridate::year(Month)", "Turnover", "sub(' Territory', '\nTerritory', State)", rotate_xlabel = TRUE) waterfall_plot(aus_retail, "lubridate::year(Month)", "Turnover", "sub(' Territory', '\nTerritory', State)", rotate_xlabel = TRUE, label_rescale = 0.5, ingroup_label = TRUE, bottom_label = FALSE, n_x = 3, size = 20, y_min = 0)