prConvert2Coords: Converts an object to coordinates

View source: R/boxGrobs_prConvert2Coords.R

prConvert2CoordsR Documentation

Converts an object to coordinates

Description

Sometimes we have an object that can be either a box, a coordinate, a unit or a numerical value and all we want is a list of coordinates that we can use for calculating distance, alignment and other things.

Usage

prConvert2Coords(obj)

Arguments

obj

A single or a list of objects. Supported element types include:

  • boxGrob or boxPropGrob

  • output from coords

  • a unit (grid) or a numeric value coercible to an npc unit

When a list is provided the function recursively converts each element and returns bounding coordinates that encompass all elements. The returned units are in npc so the coordinates resize with the viewport.

Details

When given a list, prConvert2Coords computes the min/max of edges (or uses center +/- half sizes when edges are missing) to create a merged bounding box. Any additional coordinate names present on elements are merged heuristically (for example, ⁠left*⁠ -> min, ⁠right*⁠ -> max, otherwise averaged).

Value

A list with the points produced by coords. For list inputs the function returns merged bounding coordinates (class box_coords) with units in npc.

Examples

box1 <- boxGrob("A", x = .2, y = .8)
box2 <- boxGrob("B", x = .6, y = .4)
Gmisc:::prConvert2Coords(list(box1, box2))

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