Learn R Programming

VizTest (version 0.7)

geom_foreststripe: Draw alternating row stripes for forest plots and forest tables

Description

geom_foreststripe() adds alternating horizontal background bands (“zebra striping”) to forest plots or forest tables. The stripes are drawn using the y-axis scale (rather than the data itself), which makes the geom robust to missing rows, summary rows, and faceting.

Usage

geom_foreststripe(
  mapping = NULL,
  data = NULL,
  position = "identity",
  ...,
  n_cols,
  col_gap = 1,
  start = 2L,
  fill = "grey92",
  colour = NA,
  na.rm = FALSE,
  show.legend = FALSE,
  inherit.aes = TRUE
)

Value

A ggplot2 layer object that can be added to a plot.

Arguments

mapping

Set of aesthetic mappings created by ggplot2::aes(). Usually left empty; the geom does not require data-driven aesthetics.

data

The data to be displayed in this layer. If NULL, the layer inherits the plot data; only the y scale is used.

position

Position adjustment. Defaults to "identity".

...

Additional arguments passed to the underlying GeomForestStripe.

n_cols

Integer. Number of table columns. Used to determine the horizontal extent of the stripes.

col_gap

Numeric. Spacing between table columns on the x axis.

start

Integer. Index of the first row to stripe (counting from the top of the plot). Defaults to 2L, so striping begins on the second row.

fill

Fill colour for the stripes.

colour

Border colour for the stripes. Defaults to NA (no border).

na.rm

Logical. If TRUE, silently ignores missing values.

show.legend

Logical. Whether this layer should be included in the legend. Defaults to FALSE.

inherit.aes

Logical. If FALSE, the layer does not inherit aesthetic mappings from the parent plot.

Details

This geom is designed to work with both the forest figure panel (estimates and confidence intervals) and the forest table panel produced by geom_foresttable(). Because stripes are computed from the panel scales, the two panels remain visually aligned when composed with patchwork.

The stripes are computed from the panel’s y range rather than the data rows. For discrete y scales, this corresponds to the integer row positions used by ggplot2. Every other row is selected starting at start.

Horizontal extents are derived from the panel x range, allowing the stripes to span both table columns and forest-plot panels without requiring explicit xmin/xmax aesthetics.

See Also

geom_foresttable(), geom_forestpoint(), gg_forest()