Learn R Programming

VizTest (version 0.7)

scale_x_foresttable: X scale for forest tables with column headers on the top axis

Description

scale_x_foresttable() constructs a continuous x scale designed for use with geom_foresttable(). It places table column headers on the top axis tick labels, sets appropriate breaks and limits based on the requested columns, and ensures consistent spacing so that table panels align cleanly with forest plots when composed using patchwork.

Usage

scale_x_foresttable(
  cols,
  col_labels = NULL,
  col_gap = 1,
  position = "top",
  expand = ggplot2::expansion(mult = c(0, 0)),
  limits = NULL,
  ...
)

Value

A ggplot2 scale object suitable for addition to a plot.

Arguments

cols

Character vector of column names corresponding to the table columns. Determines the number, order, and spacing of x-axis breaks.

col_labels

Optional character vector giving display labels for each column. If unnamed, must be the same length as cols and is assumed to be in the same order. If named, names are matched to cols.

col_gap

Numeric. Spacing between adjacent columns on the x axis.

position

Character. Position of the x axis; defaults to "top".

expand

Expansion applied to the x scale. Defaults to no expansion (expansion(mult = c(0, 0))).

limits

Optional numeric vector of length 2 giving explicit x-axis limits. If NULL, limits are computed automatically to bracket all columns.

...

Additional arguments passed to ggplot2::scale_x_continuous().

Details

The scale uses numeric x positions internally (one per column), which allows precise control over column spacing and alignment.

This scale is typically paired with geom_foresttable() and a void theme (theme_void()) to create a table-like panel whose headers are rendered as axis labels. Because headers are true axis labels, ggplot2 can align the table panel perfectly with a forest plot panel when combining plots.

See Also

geom_foresttable(), gg_forest()