{grid}R Documentation

Draw a Group


These functions define and draw one or more groups, where a group is a grob that is drawn in isolation before being combined with the main image. The concept of groups allows for compositing operators, object reuse, and affine transformations (see the Details section).


groupGrob(src, op = "over", dst = NULL,
          name = NULL, gp=gpar(), vp=NULL), op = "over", dst = NULL,
           name = NULL, gp=gpar(), vp=NULL)

defineGrob(src, op = "over", dst = NULL,
           name = NULL, gp=gpar(), vp=NULL) 
grid.define(src, op = "over", dst = NULL,
            name = NULL, gp=gpar(), vp=NULL)

useGrob(group, transform=viewportTransform,
        name=NULL, gp=gpar(), vp=NULL) 

grid.use(group, transform=viewportTransform,
         name=NULL, gp=gpar(), vp=NULL) 



A grob.


The name of a compositing operator (see Details).


A grob.


A character identified referring to the name of a defined group.


A function that returns an affine transformation matrix; see viewportTransform.


A character identifier.


An object of class "gpar", typically the output from a call to the function gpar. This is basically a list of graphical parameter settings.


A Grid viewport object (or NULL).


In the simplest usage, we can use to specify a grob to be drawn in isolation before being combined with the main image. This can be different from normal drawing if, for example, the grob draws more than one shape and there is a mask currently in effect.

Another possible use of is to specify both src and dst and combine them using a compositing operator other than the default "over", before combining the result with the main image. For example, if we use the "clear" operator then dst is only drawn where it is NOT overlapped by src.

It is also possible to break the process into two steps by first using grid.define() to define a group and then grid.use() to draw the group. This allows for reuse of a group (define the group once and use it several times).

If a group is defined in one viewport and used in a different viewport, an implicit transformation is applied. This could be a simple transformation (if the viewports are in different locations, but are the same size), or it could be more complex if the viewports are also different sizes or at different orientations.

NOTE: transformations occur on the graphics device so affect all aspects of drawing. For example, text and line widths are transformed as well as locations.

See viewportTransform for more information about transformations and how to customise them.

Not all graphics devices support these functions: for example xfig and pictex do not. For devices that do provide support, that support may only be partial (e.g., the Cairo-based devices support more compositing operators than the pdf() device).


A grob object.


Paul Murrell

See Also



## NOTE: on devices without support for groups (or masks or patterns),
##       there will only be two overlapping opaque circles 
pat <- pattern(rasterGrob(matrix(c(.5, 1, 1, .5), nrow=2),
                          width=unit(1, "cm"),
                          height=unit(1, "cm"),
               width=unit(1, "cm"), height=unit(1, "cm"),
grid.rect(gp=gpar(col=NA, fill=pat))
mask <- rectGrob(gp=gpar(col=NA, fill=rgb(0,0,0,.5)))
pushViewport(viewport(y=.5, height=.5, just="bottom")), r=.45, gp=gpar(fill=2:3))
pushViewport(viewport(y=0, height=.5, just="bottom")), r=.45, gp=gpar(fill=2:3)))

[Package grid version 4.2.0 Index]