View source: R/boxGrobs_s3_align.R
| align | R Documentation |
Aligns a set of boxGrob/boxPropGrob according to the first positional argument.
Align a list of boxes vertically or horizontally. Designed for piping ('|>').
alignVertical(
reference,
...,
position = c("center", "top", "bottom"),
subelement = NULL
)
alignHorizontal(
reference,
...,
position = c("center", "left", "right"),
sub_position = c("none", "left", "right"),
subelement = NULL
)
align(x, ...)
## Default S3 method:
align(x, ...)
## S3 method for class 'list'
align(x, ...)
## S3 method for class 'Gmisc_list_of_boxes'
align(x, ..., axis = c("y", "x", "vertical", "horizontal"))
reference |
A |
... |
Arguments passed to ['alignVertical'] or ['alignHorizontal']. |
position |
How to align the boxes, differs slightly for vertical and horizontal alignment see the accepted arguments |
subelement |
If a |
sub_position |
When the box is a |
x |
A 'list' of boxes. |
axis |
Orientation: '"y"'/'"vertical"' or '"x"'/'"horizontal"'. |
list with the boxes that are to be aligned
The aligned list of boxes (class 'Gmisc_list_of_boxes').
Other flowchart components:
append(),
boxGrob(),
boxHeaderGrob(),
boxPropGrob(),
boxShapes,
connectGrob(),
coords(),
distance(),
flowchart(),
insert(),
move(),
moveBox(),
spread()
Other flowchart components:
append(),
boxGrob(),
boxHeaderGrob(),
boxPropGrob(),
boxShapes,
connectGrob(),
coords(),
distance(),
flowchart(),
insert(),
move(),
moveBox(),
spread()
library(grid)
grid.newpage()
# Create a reference box
box <- boxGrob("A cool reference box",
x = .5, y = .8,
box_gp = gpar(fill = "#ADB5C7")
)
# Create a group of boxes to align
boxes <- list(
another_box = boxGrob("A horizontal box", x = .1, y = .5),
yet_another_box = boxGrob("Another horizontal box", x = .8, y = .3)
)
# Align the group and then individual boxes within that group
# (do not pipe the list into the function, as the first argument is `reference`)
aligned_boxes <- alignHorizontal(boxes, reference = box, position = "right") |>
alignVertical(reference = .5, position = "center")
# Example: align a nested element inside a complex list using a deep path
complex_list <- list(
arms = list(
early = list(boxGrob("Early", x = .2, y = .4)),
late = list(boxGrob("Late", x = .8, y = .2))
),
detail = list(
list(boxGrob("D_early", x = .1, y = .6)),
list(boxGrob("D_late", x = .9, y = .1))
)
)
# Align the first detail element to the early arm by deep path
complex_list <- complex_list |>
alignHorizontal(
reference = c("arms", "early"),
position = "center",
subelement = c("detail", 1)
)
# Print the reference and the aligned boxes
box
aligned_boxes
complex_list
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.