gglasagna: Lasagna plots for 'tf's using 'ggplot2'

View source: R/gglasagna.R

gglasagnaR Documentation

Lasagna plots for tfs using ggplot2

Description

Lasagna plots show one color bar for each function.

Usage

gglasagna(
  data,
  tf,
  order = NULL,
  label = NULL,
  arg = NULL,
  order_by = NULL,
  order_ticks = TRUE
)

Arguments

data

A data frame containing the tf column to visualize.

tf

bare name of the tf column to visualize

order

(optional) bare name of a column in data to define vertical order of lasagna layers.

label

(optional) bare name of a column in data to define labels for lasagna layers. Defaults to names of y, if present, or row numbers.

arg

arg to evaluate y on

order_by

a function applied to each row in y[, arg] that must return a scalar value to define the order of lasagna layers.

order_ticks

add horizontal lines indicating borders between levels of order (if it is a discrete variable) and labels for its levels? Defaults to TRUE. Supply a named list to override tick appearance, including label styling, line type, alpha, rotation, and label placement. Disable this when faceting; the tick annotations are not designed for faceted layouts.

Details

The vertical order of the lasagna layers is increasing in

  • order (if provided),

  • the values returned by order_by (if provided),

  • and the row number of the observations.

i.e., lowest values are on top so that by default the first layer is the first observation in data and the vertical order of the layers is the ordering of observations obtained by dplyr::arrange(data, order, order_by(value), row_number()).

Value

a ggplot2 object

See Also

Other tidyfun visualization: autoplot.tf(), ggcapellini, ggspaghetti

Examples


library(ggplot2)
set.seed(1221)
data <- expand.grid(group = factor(1:5), rep = 1:10)
data <- dplyr::mutate(data,
  id = paste(group, rep, sep = "-"),
  f = tf_rgp(50),
  fb = tfb(f)
)

gglasagna(data, f, label = id)
gglasagna(data, fb, label = id, order = group)
# order is lowest first / on top by default
gglasagna(data, f, label = id, order = tf_depth(f))
gglasagna(data, f, label = id, order_by = dplyr::first) +
  facet_wrap(~group, scales = "free")
# order of layers is by "order_by" within "order":
gglasagna(data, fb, label = id, order = group, order_by = dplyr::first)


tidyfun documentation built on April 24, 2026, 5:06 p.m.