Graphics Reference
In-Depth Information
is made available for others to use in exactly the same way as existing plots. To be
more explicit, in an extensible system you can create a new menu item or function
that other users can access.
So what sorts of features are necessary or desirable to support the development
of new plots? For a start, the system must allow new functions or menu items to be
added, and these must be able to be added by the user.henextmostimportantfea-
tures are that low-level building blocks must be available and there must be support
for combining those building blocks into larger, coherent graphical elements (plots).
Building Blocks
3.3.1
What are the fundamental building blocks from which plots are made? At the low-
est level, a plot is simply basic graphical shapes and text, so these must be available
(see 'Graphical Primitives' in Sect. . . ).In addition, there must be some way to de-
fine coordinate systems so that graphical elements can be conveniently positioned
in sensible locations to make up a plot. Surprisingly, that's about it. Given the ability
to draw shapes and locate them conveniently, you can produce a huge variety of re-
sults.Controlling coordinate systemsisaspecial caseofbeingable todefinearbitrary
transformations on output, such as is provided by the current transformation matrix
in PostScript or transform attributes on group elements in SVG.
We have already seen that R provides basic graphical elements such as lines and
text (Sect. . . ). R also provides ways to control coordinate systems; this discussion
will focus on the features provided bythe grid system because they are more flexible.
he grid system in R provides the concept of a 'viewport', which represents a rect-
angular region on the page and contains several different coordinate systems. View-
portscanbenested(positionedwithineachother)toproducequitecomplexarrange-
ments of regions. he following code provides a simple demonstration (Fig. . ).
First of all, we create a region centred on the page, but only % as wide and high as
the page.
> pushViewport(viewport(width=0.8, height=0.8,
xscale=c(0, 3), yscale=c(0, 10)))
his now is where drawing occurs, so rectangles and axes are drawn relative to this
viewport.
> grid.rect(gp=gpar(fill="light grey"))
> grid.xaxis(at=1:2, gp=gpar(cex=0.5))
> grid.yaxis(gp=gpar(cex=0.5))
Now we define a new viewport, which is located at
relative to the axis scales
of the first viewport. his also demonstrates the idea of multiple coordinate systems;
the width and height of this new viewport are specified in terms of absolute units,
rather than relative to the axis scales of the previous viewport.
> pushViewport(viewport(unit(1, "native"),
unit(4, "native"),
width=unit(1, "cm"),
height=unit(1, "inches")))
(
,
)
Search WWH ::




Custom Search