add.layout {snippets}R Documentation

Functions designed to create non-overlaping layout of rectangles or labels.


add.layout creates or adds to a layout of non-overlapping rectangles.

add.labels is a front-end to add.layout which creates a layout suitable for labels allowing to adjust the placement of the label with respect to the original points and to add extra margins.


add.layout(x, y, w, h, rs = 0.01, as = 0.22, ri = 0, ai = 0, l = NULL)
add.labels(x, y, txt, w, h, adj = 0.5, mar = 0.1, ...)



x coordinates of the points to add. For rectangles it is the left edge.


y coordinates of the points to add. For rectangles it is the bottom edge.


width of the rectangles (optional for labels where it defaults to the label widths)


height of the rectangles (optional for labels where it defaults to the label height)


radius step for the placement algorithm


angle step for the placement algorithm


initial radius for the placement algorithm


initial angle for the placement algorithm


layout to add to or NULL if a new layout is to be created


text labels to add


adjustment of the text position with respect to the supplied points (see adj in text)


additional margins around the text (relative to the width or height). If present, it will be recycled to length two for horizontal and vertical margins respectively.


additional parameters passed through to add.layout


The layout attempts to sequentially place rectangles of the given width and height at the specified points. If a placement of a new rectangle would overlap with any existing rectangle, it is moved until it no longer overlaps. The current algorithm defines the movement as a clockwise spiral.


add.layout returns an obejct of the class box.layout which consists of a list with elements x, y, w and h. If the input was non-overlapping it would be equivalent to the (recycled) arguments. If there are overlaps the x and y coordinates will differ accordingly.

If l is specified on input, it is expected to be box.layout as well and the layout is extended by adding the rectangles defined in the arguments.

add.labels returns an object of the class label.layout which is a subclass of box.layout. It adds the components lx and ly which are the label coordinates (as opposed to the rectangle coordinates). If adj is zero the label and box coordinates are equal.


x = rnorm(100)
y = rnorm(100)
txt = sprintf("%.2f", rnorm(100))
plot(x, y, pch=3, col=2)
l = add.labels(x, y, txt, mar=0.2)
rect(l$x, l$y, l$x + l$w, l$y + l$h, col="#00000020", border=NA)
text(l$lx, l$ly, txt, col=4)
segments(x, y, l$lx, l$ly, col=3)

[Package snippets version 0.1-1 Index]