lt_sparkline: Draw an inline sparkline in a column

View source: R/tab.R

lt_sparklineR Documentation

Draw an inline sparkline in a column

Description

Render a per-row series of numbers as a small inline SVG line or bar chart (a sparkline). The series for each row can come from a single list-column (each element a numeric vector) or from several numeric columns read across the row. Like lt_errorbar(), it is lightweight: 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_sparkline(
  x,
  columns,
  type = c("line", "bar"),
  limits = NULL,
  color = NULL,
  width = 120,
  height = 20,
  hide = TRUE
)

Arguments

x

An lt() object.

columns

The column(s) holding each row's series. Either a single list-column (a one-sided formula ~ col, a name, or a position) whose cells are numeric vectors, or several numeric columns (~ a + b + c) whose values are read left to right as the series. The sparkline is drawn in the first column's cells.

type

"line" (default) for a line chart or "bar" for a bar chart.

limits

Numeric c(min, max) for a shared vertical scale across all rows (so rows are comparable). The default (NULL) scales each row to its own range.

color

CSS color for the line or bars (defaults to the stylesheet's).

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()).

hide

If TRUE (default) and the series spans several columns, those columns after the first are hidden (their values are drawn into the plot); set to FALSE to keep them visible. Has no effect for a single list-column.

Value

x with the sparkline column recorded.

Examples

# a list-column: each cell is a numeric vector
d = data.frame(city = c("A", "B", "C"))
d$temp = list(c(3, 5, 8, 6, 9), c(1, 2, 2, 4, 3), c(7, 6, 5, 6, 8))
lt(d) |> lt_sparkline(~ temp)
# several columns read across the row, as bars on a shared scale
m = data.frame(name = c("X", "Y"), q1 = c(2, 5), q2 = c(4, 3),
  q3 = c(6, 7), q4 = c(5, 2))
lt(m) |> lt_sparkline(~ q1 + q2 + q3 + q4, type = "bar", limits = c(0, 8))

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