lt_dotplot: Draw an inline dot plot in a column

View source: R/tab.R

lt_dotplotR Documentation

Draw an inline dot plot in a column

Description

Render each row's values across one or more columns as inline dots on a shared horizontal scale: N columns give N dots per row, laid out by value. It is lightweight like lt_errorbar() and lt_sparkline() – only the numbers travel to the client and the SVG is drawn in the browser, so an interactive table (lt_interactive()) draws only the rows on the current page.

Usage

lt_dotplot(
  x,
  columns,
  limits = NULL,
  color = FALSE,
  labels = NULL,
  stagger = FALSE,
  into = NULL,
  width = 160,
  height = NULL,
  hide = TRUE,
  axis = TRUE
)

Arguments

x

An lt() object.

columns

The value column(s): one dot is drawn per column, read left to right across the row, all on a scale shared across the columns. The plot is drawn in the first column's cells, or into into when given. A one-sided formula (~ a + b + c), names, or integer positions.

limits

Numeric c(min, max) for the shared horizontal scale. Defaults to the range of all the columns' finite values. Values outside the scale are clamped to the edges.

color

Series colors. FALSE (default) draws every series in one default color; TRUE assigns colors from the current palette (grDevices::palette()); a character vector of CSS colors sets them explicitly (recycled to the number of series). When colored, a legend is drawn below the plot in the footer.

labels

Legend labels, one per series, used when colored. Defaults to the series' value-column names.

stagger

If TRUE, spread the dots onto separate vertical tracks (one per column) instead of a single baseline, so near-equal values do not overlap. The vertical position is only cosmetic separation; the value is still read horizontally. The cell is made taller to fit the tracks (unless height is set). FALSE (default) draws all dots on one line.

into

Optional name of a dedicated column to draw the plot into, instead of the first series' value column. The series columns (...) are still read for their values and stay visible unless hide drops them, so you can show every value column as text and a plot in its own column. A column of this name is created when it does not already exist (added as a new, extra column – use lt_move() to position it). When NULL (default), the plot is drawn into the first series' value column.

width, height

Pixel size of each cell's SVG. width may instead be a relative CSS width (e.g. "100%"), or list(min =, width =), to auto-fit the column (see lt_errorbar()). height defaults to a size that fits the tracks when stagger is set, else a single line.

hide

If TRUE (default), the columns the plot reads are hidden, since their values are drawn into it: all but the one holding the plot, or – when into names a separate target column – all of them. Set to FALSE to keep them visible.

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. TRUE draws the axis; a character string draws the axis with that string as a caption below it (e.g. "Risk difference"); FALSE (default) draws no axis.

Details

Since the cell shows every named column, the column header defaults to all their names joined by " / " (e.g. "Before / After"); override it with a later lt_label() on that column.

Value

x with the dot-plot column recorded.

Examples

d = data.frame(
  group = c("A", "B", "C"), before = c(3, 5, 4), after = c(6, 7, 5)
)
# one dot per column, colored and keyed by a footer legend, with an axis
lt(d) |> lt_dotplot(~ before + after, color = TRUE)
# custom colors and labels
lt(d) |> lt_dotplot(
  ~ before + after, color = c("#999", "#1a9641"),
  labels = c("Baseline", "Follow-up")
)
# draw into a dedicated column, keeping the value columns visible as text
lt(d) |> lt_dotplot(~ before + after, into = "plot", hide = FALSE)

lt documentation built on Oct. 17, 2026, 9:06 a.m.