boxShapes: Additional box shape helpers for 'boxGrob'

boxShapesR Documentation

Additional box shape helpers for 'boxGrob'

Description

These helper functions provide alternative box drawing functions that can be passed to 'boxGrob(..., box_fn = ...)' or used via convenience wrappers ('boxDiamondGrob', 'boxEllipseGrob', 'boxRackGrob'). They are intentionally lightweight and implemented using base 'grid' primitives.

Two diamond variants are provided: a rounded diamond (default) implemented with 'xsplineGrob' for slightly softened corners, and a sharp diamond implemented with 'polygonGrob' for strict straight edges.

Approximates an ellipse using a polygon with many points; it respects the box viewport so it scales correctly.

A rectangular box with a slightly darker top band to mimic a server / disk rack look. Implemented by composing a rounded rectangle and an overlaying top strip. The strip is drawn without border to avoid double outlines.

Draws a cylinder-like database symbol (ellipse top, rectangular body, base ellipse).

A document icon with a wavy bottom edge, useful to indicate printed output.

Draws a stack of document shapes by repeating the same shape with offsets.

Left/right curved edges to mimic tape-like icons.

A server-styled box with front-panel vent lines so it is visually distinct from a rack (top strip) representation.

Usage

diamond_rounded_box_fn(x = 0.5, y = 0.5, gp = gpar())

diamond_sharp_box_fn(x = 0.5, y = 0.5, gp = gpar())

boxDiamondGrob(
  label,
  y = unit(0.5, "npc"),
  x = unit(0.5, "npc"),
  width,
  height,
  just = "center",
  bjust = "center",
  txt_gp = getOption("boxGrobTxt", default = gpar(color = "black", cex = 1)),
  box_gp = getOption("boxGrob", default = gpar(fill = "white")),
  rounded = TRUE,
  name = NULL
)

ellipse_box_fn(x = 0.5, y = 0.5, gp = gpar())

boxEllipseGrob(
  label,
  y = unit(0.5, "npc"),
  x = unit(0.5, "npc"),
  width,
  height,
  just = "center",
  bjust = "center",
  txt_gp = getOption("boxGrobTxt", default = gpar(color = "black", cex = 1)),
  box_gp = getOption("boxGrob", default = gpar(fill = "white")),
  name = NULL
)

rack_box_fn(x = 0.5, y = 0.5, gp = gpar())

boxRackGrob(
  label,
  y = unit(0.5, "npc"),
  x = unit(0.5, "npc"),
  width,
  height,
  just = "center",
  bjust = "center",
  txt_gp = getOption("boxGrobTxt", default = gpar(color = "black", cex = 1)),
  box_gp = getOption("boxGrob", default = gpar(fill = "white")),
  name = NULL
)

database_box_fn(x = 0.5, y = 0.5, gp = gpar())

boxDatabaseGrob(
  label,
  y = unit(0.5, "npc"),
  x = unit(0.5, "npc"),
  width,
  height,
  just = "center",
  bjust = "center",
  txt_gp = getOption("boxGrobTxt", default = gpar(color = "black", cex = 1)),
  box_gp = getOption("boxGrob", default = gpar(fill = "white")),
  name = NULL
)

document_box_fn(x = 0.5, y = 0.5, gp = gpar())

boxDocumentGrob(
  label,
  y = unit(0.5, "npc"),
  x = unit(0.5, "npc"),
  width,
  height,
  just = "center",
  bjust = "center",
  txt_gp = getOption("boxGrobTxt", default = gpar(color = "black", cex = 1)),
  box_gp = getOption("boxGrob", default = gpar(fill = "white")),
  name = NULL
)

documents_box_fn(x = 0.5, y = 0.5, gp = gpar())

boxDocumentsGrob(
  label,
  y = unit(0.5, "npc"),
  x = unit(0.5, "npc"),
  width,
  height,
  just = "center",
  bjust = "center",
  txt_gp = getOption("boxGrobTxt", default = gpar(color = "black", cex = 1)),
  box_gp = getOption("boxGrob", default = gpar(fill = "white")),
  name = NULL
)

tape_box_fn(x = 0.5, y = 0.5, gp = gpar())

boxTapeGrob(
  label,
  y = unit(0.5, "npc"),
  x = unit(0.5, "npc"),
  width,
  height,
  just = "center",
  bjust = "center",
  txt_gp = getOption("boxGrobTxt", default = gpar(color = "black", cex = 1)),
  box_gp = getOption("boxGrob", default = gpar(fill = "white")),
  name = NULL
)

server_box_fn(x = 0.5, y = 0.5, gp = gpar())

boxServerGrob(
  label,
  y = unit(0.5, "npc"),
  x = unit(0.5, "npc"),
  width,
  height,
  just = "center",
  bjust = "center",
  txt_gp = getOption("boxGrobTxt", default = gpar(color = "black", cex = 1)),
  box_gp = getOption("boxGrob", default = gpar(fill = "white")),
  name = NULL
)

Arguments

x

Horizontal position inside the box viewport (0-1).

y

Vertical position inside the box viewport (0-1).

gp

A 'gpar' object with styling information (fill/col/etc).

label

The label to print - should be a number, text or expression.

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

just

The justification for the text: left, center or right.

bjust

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

txt_gp

The gpar style to apply to the text. Set boxGrobTxt option if you want to customize all the boxes at once.

box_gp

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

rounded

Logical; use rounded diamond (TRUE) or sharp diamond (FALSE).

name

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

Details

Shape functions are called with 'x' and 'y' in [0,1] inside the box viewport and with 'box_gp' for styling; convenience wrappers match the 'boxGrob' signature.

Value

A 'grid' grob that draws the requested shape inside the box viewport.

See Also

boxGrob for usage and the 'box_fn' argument

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

Examples

# These functions are designed to be passed to `boxGrob(..., box_fn = ...)`.
grid::grid.newpage()
d <- boxGrob("Decision", box_fn = diamond_rounded_box_fn)
e <- boxGrob("Start", box_fn = ellipse_box_fn)
r <- boxGrob("Server", box_fn = rack_box_fn)
spreadHorizontal(list(d, e, r))

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