bcat_plt_line: Line plot utility

View source: R/bcat_plt_line.R

bcat_plt_lineR Documentation

Line plot utility

Description

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

Usage

bcat_plt_line(
  df,
  x,
  y,
  color = NULL,
  linetype = NULL,
  facet = NULL,
  x_lab = ggplot2::waiver(),
  y_lab = ggplot2::waiver(),
  title = ggplot2::waiver(),
  subtitle = ggplot2::waiver(),
  caption = ggplot2::waiver(),
  legend_lab = ggplot2::waiver(),
  legend_position = "bottom",
  legend_hide = FALSE,
  x_scale = NULL,
  y_scale = NULL,
  color_scale = Rbearcat::scale_colour_UC(),
  facet_scale = c("fixed", "free_y", "free_x", "free"),
  nrow = NULL,
  ncol = NULL,
  layer_points = FALSE,
  x_refline = NULL,
  y_refline = NULL,
  x_highlight_min = NULL,
  x_highlight_max = NULL,
  y_highlight_min = NULL,
  y_highlight_max = NULL,
  y_ribbon_min = NULL,
  y_ribbon_max = NULL,
  y_error_min = NULL,
  y_error_max = NULL,
  y_error_width = 1
)

Arguments

df

The data to be displayed

x

Variable to map to the x-axis

y

Variable to map to the y-axis

color

Variable to map to the color aesthetic

linetype

Variable to map to the linetype aesthetic

facet

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

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.

y_scale

scale_y_ function to apply to y-axis.

color_scale

scale_color_ 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

layer_points

Set to TRUE to plot points

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

x_highlight_min

Vector of min x-values at which to start draw rectangle annotation

x_highlight_max

Vector of max x-values at which to end rectangle annotation

y_highlight_min

Vector of min y-values at which to start draw rectangle annotation

y_highlight_max

Vector of max y-values at which to end rectangle annotation

y_ribbon_min

Variable to use as minimum values for ribbon around y at each value of x

y_ribbon_max

Variable to use as maximum values for ribbon around y at each value of x

y_error_min

Variable to use as minimum values for error bars around y at each value of x

y_error_max

Variable to use as maximum values for error bars around y at each value of x

y_error_width

Width of error bars

Value

A ggplot2 plot object.

Author(s)

Saannidhya Rawat

See Also

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

Examples

library(ggplot2)
library(scales)

# basic time series plot with a reference line
bcat_plt_line(df = economics,
              x = date,
              y = unemploy,
              y_scale = scale_y_continuous(labels = comma_format()),
              y_refline = 10000)

# line plot with facets and highlight periods
bcat_plt_line(df = economics_long,
             x = date,
             y = value,
             color = variable,
             facet = vars(variable),
             x_lab = "Decade",
             y_lab = "Value",
             legend_lab = NULL,
             facet_scale = "free_y",
             x_highlight_min = as.Date(c("2000-01-01", "2008-01-01")),
             x_highlight_max = as.Date(c("2002-01-01", "2010-01-01")),
             ncol = 1)


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