grid.reduce: Reduce Multiple Shapes to a Single Shape

View source: R/grid.R

grid.reduceR Documentation

Reduce Multiple Shapes to a Single Shape

Description

This function takes a grob (or gTree) that draws multiple shapes and reduces it to a grob that only draws one shape.

More accurately, the result only draws at most one closed shape and at most one open shape.

Usage

reduceGrob(x, op=if (isClosedShape(x)) "union" else "flatten",
           openFn=xyListToLine, closedFn=xyListToPath,
           name=NULL, gp=gpar()) 
grid.reduce(x, ...)

Arguments

x

A grob, gList, or gTree, or a gPath or a character value identifying a grob that has already been drawn.

op

A character value describing the operation. One of "intersection", "minus", "union", "xor", or "flatten".

openFn

The function used to create grobs from the open shapes in the result.

closedFn

The function used to create grobs from the closed shapes in the result.

name

A name for the resulting grob.

gp

Graphical parameter settings for the resulting grob.

...

For reduceGrob, arguments passed on to polyclip. For grid.reduce, arguments used by methods.

Details

Multiple shapes are combined using polyclip() and the specified operator op.

Value

reduceGrob returns a gTree with two children, one representing the open shapes within the result and one representing the closed shapes within the result.

grid.reduce is only used for its side-effect of drawing on the current graphics device.

Author(s)

Paul Murrell

See Also

grid.polyclip

Examples

r <- rectGrob(x=1/3, y=1/3, width=.4, height=.4)
c <- circleGrob(x=2/3, y=2/3, r=.3)
grid.reduce(grobTree(r, c), gp=gpar(fill="grey"))

gridGeometry documentation built on Sept. 11, 2024, 8:41 p.m.