View source: R/boxGrobs_s3_spread.R
| spread | R Documentation |
Spread a list of boxes vertically or horizontally. Designed for piping ('|>').
Spreads a set of boxGrob/boxPropGrob in either horizontal or vertical
direction within a given span.
spread(x, ...)
## Default S3 method:
spread(x, ...)
## S3 method for class 'list'
spread(x, ...)
## S3 method for class 'Gmisc_list_of_boxes'
spread(x, ..., axis = c("y", "x", "vertical", "horizontal"))
spreadVertical(
...,
from = NULL,
to = NULL,
margin = unit(0, "npc"),
type = c("between", "center"),
subelement = NULL
)
spreadHorizontal(
...,
from = NULL,
to = NULL,
margin = unit(0, "npc"),
type = c("between", "center"),
subelement = NULL
)
x |
A 'list' of boxes. |
... |
A set of boxes to spread. Can also be a |
axis |
Orientation: '"y"'/'"vertical"' or '"x"'/'"horizontal"'. |
from |
Starting point of the span. Can be a box, a coordinate/unit, or a
numeric value interpreted as |
to |
Ending point of the span. Can be a box, a coordinate/unit, or a
numeric value interpreted as |
margin |
Optional padding applied at both ends of the span. Can be a
|
type |
If |
subelement |
If a |
The span can be defined explicitly using from / to, or implicitly by the
current viewport. Numeric values are interpreted as proportions of the viewport
(npc units).
The list of boxes with updated positions (class 'Gmisc_list_of_boxes').
A list with the boxes that have been spread.
Other flowchart components:
align(),
append(),
boxGrob(),
boxHeaderGrob(),
boxPropGrob(),
boxShapes,
connectGrob(),
coords(),
distance(),
flowchart(),
insert(),
move(),
moveBox()
Other flowchart components:
align(),
append(),
boxGrob(),
boxHeaderGrob(),
boxPropGrob(),
boxShapes,
connectGrob(),
coords(),
distance(),
flowchart(),
insert(),
move(),
moveBox()
library(grid)
grid.newpage()
# Create a set of boxes
start <- boxGrob("Top", x = .5, y = .8)
end <- boxGrob("Bottom", x = .5, y = .2)
side <- boxPropGrob("Side", "Left", "Right", prop = .3, x = .2, y = .8)
exclude <- boxGrob("Exclude:\n - Too sick\n - Prev. surgery", x = .8, y = .5, just = "left")
# We can chain the spread operations and print the result
spreadVertical(
start = start,
middle = list(side, exclude),
end = end
) |>
spreadHorizontal(subelement = "middle", from = 0.2, to = 0.8)
# Use device-level paging in interactive sessions so users can inspect the first plot
# This will prompt before creating the next page; we restore the previous setting afterwards
if (interactive()) {
old_ask <- grDevices::devAskNewPage(TRUE)
on.exit(grDevices::devAskNewPage(old_ask), add = TRUE)
grid.newpage() # will prompt on interactive devices
} else {
# non-interactive: just start a fresh page for the next example
grid.newpage()
}
# Example: spread a nested subelement by deep path and print sequentially
list(grp = list(middle = list(side, exclude))) |>
spreadHorizontal(subelement = c("grp", "middle"), from = 0.2, to = 0.8)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.