distance: Get the distance between grid objects

View source: R/boxGrobs_distance.R

distanceR Documentation

Get the distance between grid objects

Description

Retrieves the distance between two boxes as absolute "mm" units. The function also accepts coords objects as well as a unit or a numeric input.

Usage

distance(
  box1,
  box2,
  type = c("vertical", "horizontal", "euclidean"),
  half = FALSE,
  center = FALSE
)

## S3 method for class 'Gmisc_unit'
print(x, ...)

Arguments

box1

The first boxGrob. Can also be a coords object, a unit or a numeric. The latter is evaluated to a unit with units="npc".

box2

The second object to calculate the distance to. Same type as for box1.

type

Whether we should retrieve the vertical, horizontal or euclidean distance

half

If set to true it returns half the distance. This is convenient when positioning boxes between each other.

center

Calculate the distance from the center of each object

x

A unit with from the distance function

...

Passed on to print

Value

A unit in "mm" with an absolute value. The attribute positive indicates the direction of the value, i.e. if it is TRUE the distance was calculated from the first to the second, otherwise it is FALSE. For euclidean distance the positive attribute is NA. There is also the from and to attributes that has the coordinates that were used for the calculations, for euclidean distance this is NA.

See Also

Other flowchart components: align, boxGrob(), boxPropGrob(), connectGrob(), coords(), moveBox(), spread

Examples

box1 <- boxGrob("A test box", y = .8)
box2 <- boxGrob("Another test box", y = .2)
distance(box1, box2, "v")

gforge/Gmisc documentation built on Aug. 30, 2023, 7:38 a.m.