| lt_errorbar | R Documentation |
Render a numeric column's cells as a small inline SVG: a point at the
estimate and a horizontal bar (with end caps) from the lower to the upper
bound, drawn on a scale shared across the column so rows are comparable at a
glance (handy for
a forest plot of effect sizes with confidence intervals). It is lightweight:
only the numbers travel to the client, and the SVG is drawn in the browser —
so for an interactive table (lt_interactive()) only the rows on the current
page are drawn.
lt_errorbar(
x,
...,
limits = NULL,
ref = NULL,
into = NULL,
width = 160,
height = NULL,
hide = TRUE,
axis = FALSE,
color = FALSE,
labels = NULL
)
x |
An |
... |
One or more error-bar series, each naming the point estimate, the
lower bound, and the upper bound, in that order: either a two-sided formula
|
limits |
Numeric |
ref |
Optional value at which to draw a vertical reference line (e.g.
|
into |
Optional name of a dedicated column to draw the plot into,
instead of the first series' value column. The series columns ( |
width, height |
Pixel size of each cell's SVG. |
hide |
If |
axis |
Draw a shared horizontal axis (a baseline with tick marks and
labels at "nice" round values) in the table footer under the plot column,
plus faint vertical gridlines inside each cell at the same tick positions
to help read the bars. |
color |
Series colors. |
labels |
Legend labels, one per series, used when colored. Defaults to the series' value-column names. |
Several series can share one cell: pass one triple per series and each row
shows one point-and-bar per series, stacked vertically on the same shared
scale (e.g. a risk difference for each of several treatment arms). Color the
series and a legend is drawn in the footer, as for lt_dotplot().
x with the error-bar column recorded.
d = data.frame(
term = c("A", "B", "C"), est = c(0.2, -0.1, 0.4),
lo = c(0.0, -0.3, 0.1), hi = c(0.4, 0.1, 0.7)
)
# a two-sided formula names the estimate (LHS) and the bounds (RHS)
lt(d) |> lt_errorbar(est ~ lo + hi, ref = 0)
# keep the bounds columns visible and add a labeled axis
lt(d) |> lt_errorbar(est ~ lo + hi, hide = FALSE, axis = "Effect")
# draw into a dedicated column, keeping every value column visible as text
lt(d) |> lt_errorbar(est ~ lo + hi, into = "forest", hide = FALSE)
# auto-fit the plot to its column (grows/shrinks as the column is resized)
lt(d) |> lt_errorbar(est ~ lo + hi, into = "forest", width = "100%")
# several series stacked in each cell, colored with a footer legend
d2 = data.frame(
term = c("A", "B"), e1 = c(0.2, 0.4), l1 = c(0, 0.2), u1 = c(0.4, 0.6),
e2 = c(-0.1, 0.1), l2 = c(-0.3, -0.1), u2 = c(0.1, 0.3)
)
lt(d2) |> lt_errorbar(
e1 ~ l1 + u1, e2 ~ l2 + u2, ref = 0, color = TRUE,
labels = c("Drug A", "Drug B")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.