| geom_foresttable | R Documentation |
geom_foresttable() builds a “table” panel for forest plots by expanding the
input data to long form (one row per forest row × table column) and drawing
formatted cell text at fixed x positions. Column headers are typically added
with scale_x_foresttable() (top axis tick labels), which makes the table
align cleanly with a forest plot when composing with patchwork.
geom_foresttable(
mapping = NULL,
data = NULL,
position = "identity",
...,
cols,
fmt = NULL,
fmt_default = as.character,
col_gap = 1,
col_align = "left",
col_nudge = 0,
na.rm = FALSE,
show.legend = FALSE,
inherit.aes = TRUE
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. If |
position |
Position adjustment. Defaults to |
... |
Additional arguments passed to the underlying text geom
( |
cols |
Character vector of column names to print in the table. Must be non-empty. |
fmt |
Optional named list of formatting functions. Each function should
take a single value and return a length-1 character (or coercible) result.
Names should correspond to entries of |
fmt_default |
Default formatting function used for columns not present
in |
col_gap |
Numeric. Spacing between adjacent table columns on the x axis. |
col_align |
Character vector of alignments for each column in |
col_nudge |
Numeric vector of per-column horizontal nudges (in x-axis
units) applied to the column positions. Length 1 is recycled to
|
na.rm |
Logical. If |
show.legend |
Logical. Whether this layer should be included in legends.
Defaults to |
inherit.aes |
Logical. If |
The cols argument controls which columns are printed. Formatting can be
customized via fmt, a named list of functions (one per column) that convert
cell values to character strings.
geom_foresttable() uses ggplot2's feature where the data argument may be a
function: when data = NULL, this layer supplies a data function that receives
the plot data and expands it to long form while preserving all original
columns (including faceting variables and the y mapping). This makes the geom
compatible with faceting and grouping while keeping the user-facing API
simple.
Column positions are computed as seq_along(cols) * col_gap + col_nudge.
Horizontal justification is determined by col_align (left/center/right).
A ggplot2 layer object that can be added to a plot.
scale_x_foresttable(), gg_forest()
# geom_foresttable() is designed to be used as part of gg_forest().
# See ?gg_forest for a complete runnable example.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.