boxHeaderGrob: Create a composite box with header and body text

View source: R/boxGrobs_boxHeaderGrob.R

boxHeaderGrobR Documentation

Create a composite box with header and body text

Description

Creates a grob box with a centered header and left-justified body text. Useful for flowchart elements that combine a title with bullet points or multi-line descriptions.

Usage

boxHeaderGrob(
  header,
  body,
  y = unit(0.5, "npc"),
  x = unit(0.5, "npc"),
  width,
  height,
  bjust = "center",
  header_gp = getOption("boxHeaderGrobTxt", default = gpar(color = "black", cex = 1)),
  body_gp = getOption("boxBodyGrobTxt", default = gpar(color = "black", cex = 0.9)),
  box_gp = getOption("boxGrob", default = gpar(fill = "white")),
  box_fn = roundrectGrob,
  name = NULL
)

Arguments

header

The header text (centered, typically bold).

body

The body text (left-justified, typically with bullets or multiple lines).

y

The y position to put the box at. Can be either in npc (i.e. 0-1) or a unit.

x

The x position to put the box at. Can be either in npc (i.e. 0-1) or a unit.

width

The box automatically adapts the size but you can force by specifying the width

height

The box automatically adapts the size but you can force by specifying the height

bjust

The justification for the box: left, center, right, top or bottom. See the just option for the viewport

header_gp

The gpar style to apply to the header text. Defaults to bold text at slightly larger size.

body_gp

The gpar style to apply to the body text.

box_gp

The gpar style to apply to the box function of 'box_fn' below.

box_fn

Function to create box for the text. Parameters of 'x=0.5', 'y=0.5' and 'box_gp' will be passed to this function and return a grob object.

name

a character identifier for the grob. Used to find the grob on the display list and/or as a child of another grob.

Value

A grob with class "box" compatible with all Gmisc flowchart helpers (coords, distance, connectGrob, spreadVertical, alignHorizontal, etc.)

See Also

Other flowchart components: align(), append(), boxGrob(), boxPropGrob(), boxShapes, connectGrob(), coords(), distance(), flowchart(), insert(), move(), moveBox(), spread()

Examples

library(grid)
grid.newpage()

# Simple example with header and bullets
box1 <- boxHeaderGrob(
  header = "Early rehabilitation",
  body = paste("0-1 weeks", "• Instruction", "• Pendulum + assisted ROM", sep = "\n"),
  header_gp = gpar(fontsize = 11, fontface = "bold"),
  body_gp = gpar(fontsize = 9),
  box_gp = gpar(fill = "#E8F5E9", col = "#2E7D32")
)
grid.draw(box1)

# Works with all helpers
box2 <- boxHeaderGrob(
  header = "Delayed rehabilitation",
  body = "0-3 weeks\n• Sling immobilisation",
  y = 0.3,
  box_gp = gpar(fill = "#FFF8E1", col = "#EF6C00")
)

# Distance calculation works
d <- distance(box1, box2, type = "v")

# Connect boxes
grid.draw(box2)
connectGrob(box1, box2, type = "vertical")

Gmisc documentation built on March 6, 2026, 9:09 a.m.