This set of functions makes it easy to define shapes at the terminal points of edges that are used to shorten the edges. The shapes themselves are not drawn, but the edges will end at the boundary of the shape rather than at the node position. This is especially relevant when drawing arrows at the edges as the arrows will be partly obscured by the node unless the edge is shortened. Edge shortening is dynamic and will update as the plot is resized, making sure that the capping remains at an absolute distance to the end point.

geometry(
  type = "circle",
  width = 1,
  height = width,
  width_unit = "cm",
  height_unit = width_unit
)

circle(radius = 1, unit = "cm")

square(length = 1, unit = "cm")

ellipsis(a = 1, b = 1, a_unit = "cm", b_unit = a_unit)

rectangle(width = 1, height = 1, width_unit = "cm", height_unit = width_unit)

label_rect(label, padding = margin(1, 1, 1.5, 1, "mm"), ...)

is.geometry(x)

Arguments

type

The type of geometry to use. Currently 'circle' and 'rect' is supported.

width, height, length, radius, a, b

The dimensions of the shape.

unit, width_unit, height_unit, a_unit, b_unit

The unit for the numbers given.

label

The text to be enclosed

padding

extra size to be added around the text using the ggplot2::margin() function

...

Passed on to grid::gpar()

x

An object to test for geometry inheritance

Value

A geometry object encoding the specified shape.

Details

geometry is the base constructor, while the rest are helpers to save typing. circle creates circles width a given radius, square creates squares at a given side length, ellipsis creates ellipses with given a and b values (width and height radii), and rectangle makes rectangles of a given width and height. label_rect is a helper that, given a list of strings and potentially formatting options creates a rectangle that encloses the string.

Examples

geometry(c('circle', 'rect', 'rect'), 1:3, 3:1)
#> <ggraph_geometry[3]>
#> [1] circle(1cm, 3cm) rect(2cm, 2cm)   rect(3cm, 1cm)  

circle(1:4, 'mm')
#> <ggraph_geometry[4]>
#> [1] circle(2mm, 2mm) circle(4mm, 4mm) circle(6mm, 6mm) circle(8mm, 8mm)

label_rect(c('some', 'different', 'words'), fontsize = 18)
#> <ggraph_geometry[3]>
#> [1] rect(1.92861111111111cm, 0.708611111111111cm)
#> [2] rect(2.89709635416667cm, 0.708611111111111cm)
#> [3] rect(2.09121961805556cm, 0.708611111111111cm)