bcat_plt_area: Area plot utility

View source: R/bcat_plt_area.R

bcat_plt_areaR Documentation

Area plot utility

Description

Create an area plot using ggplot2 graphics. This function is a wrapper to create commonly used styles of area plots. Additional layers can be added to this plot as needed. More complicated plots can be creating using individual ggplot2 layers.

Usage

bcat_plt_area(
  df,
  x = NULL,
  y = NULL,
  fill = NULL,
  facet = NULL,
  position = c("stack", "fill"),
  x_lab = ggplot2::waiver(),
  y_lab = ggplot2::waiver(),
  title = ggplot2::waiver(),
  subtitle = ggplot2::waiver(),
  caption = ggplot2::waiver(),
  legend_lab = ggplot2::waiver(),
  legend_position = "right",
  legend_hide = FALSE,
  x_scale = NULL,
  y_scale = NULL,
  fill_scale = Rbearcat::scale_fill_UC(),
  facet_scale = c("fixed", "free_y", "free_x", "free"),
  nrow = NULL,
  ncol = NULL,
  x_refline = NULL,
  y_refline = NULL
)

Arguments

df

The data to be displayed

x

variable to map to the x-axis

y

Variable to map to the y-axis

fill

Variable to map to the fill aesthetic

facet

Facetting variable(s). Note: must wrap in vars, e.g, facet = vars(var1, var2)

position

Either stack values in cumulative fashion (position = "stack") or stack such that proportions at each value of x sum to 1 (position = "fill").

x_lab

Label for x-axis

y_lab

Label for y-axis

title

Plot title

subtitle

Plot subtitle

caption

Plot caption

legend_lab

Legend title

legend_position

legend position. "bottom" or "right"

legend_hide

Set to TRUE to hide the legend

x_scale

scale_x_ function to apply to x-axis. If position = "fill", it is recommended to use the expand = c(0,0) option in the x_scale.

y_scale

scale_y_ function to apply to y-axis. If position = "fill", it is recommended to use the expand = c(0,0) option in the y_scale.

fill_scale

scale_fill_ function to apply to colors.

facet_scale

Shoud facet scales be fixed ("fixed", the default), free ("free"), or free in one dimension ("free_x", "free_y")

nrow

Number of facet rows

ncol

Number of facet columns

x_refline

Vector of x-values at which to draw vertical reference lines

y_refline

Vector of y-values at which to draw horizontal reference lines

Value

A ggplot2 plot object.

Author(s)

Saannidhya Rawat

See Also

Other plots: bcat_plt_bar(), bcat_plt_box(), bcat_plt_coef(), bcat_plt_diag(), bcat_plt_hist(), bcat_plt_line(), bcat_plt_point(), bcat_plt_ts()

Examples

set.seed(1234)

d <- data.frame(t=rep(0:23,each=4),var=rep(LETTERS[1:4],4),val=round(runif(4*24,0,50)))

# stacked area plot
bcat_plt_area(df = d, x = t, y = val, fill = var,
              position = "stack",
              fill_scale = ggplot2::scale_fill_viridis_d(),
              legend_lab = NULL)

# filled area plot
bcat_plt_area(df = d, x = t, y = val, fill = var,
              position = "fill",
              fill_scale = ggplot2::scale_fill_viridis_d(),
              legend_lab = NULL)


Rbearcat documentation built on March 21, 2026, 5:07 p.m.