Tutorial: Introduction to Grid Graphics
Paul
Murrell, Department of Statistics, The University
of Auckland, New Zealand.
Abstract
R is not only a powerful statistical graphics platform
for generating statistical plots. R is also a general
purpose graphics system. It is not only possible to produce
a wide variety of plots. It is possible to produce an
infinite variety of graphical images with R. This
tutorial will present an introduction to the grid
graphics package, a lowlevel graphics system that provides
full access to the graphics facilities in R. Knowledge of this
system will allow you to make arbitrary modications to plots
produced by packages such as lattice and
ggplot2 and it will allow you to produce a range of
diagrams and data visualizations that is limited only by your
imagination.
Outline
Entré (approx. 15 min): A peek under the hood of
lattice and ggplot2 to see if grid
is hiding underneath.

A view of the grobs and viewports left behind after
lattice and ggplot2 have done their
drawing

Simple demonstration of adding new drawing or editing
existing drawing in lattice and ggplot2
plots
Main (approx. 2 hrs, with 15 min break in middle): The
fundamentals of grid

Graphical primitives (lines, rectangles, polygons, circles,
text, roundrects, Xsplines, paths, rasters).

Graphical parameters (colours, fonts, line types).

Units and coordinate systems.

Viewports (pushing, navigating, clipping) and layouts.

Grobs (creating, querying, and editing).
This section will be illustrated and motivated by the task of
producing a custom data visualization. There will also be small
exercises for attendees to work on.
Dessert (approx. 15 min): Example applications of
grid

Editing a lattice plot to modify line endings

Adding a custom axis to a lattice plot

Customising a ggplot2 legend
Prerequisites
This course will not be appropriate for complete R newbies. It
will be assumed that the audience is familiar with R and
comfortable writing R expressions. On the other hand, no
statistical or graphical expertise will be required.
Attendees are expected to bring laptops with R installed so
that they can attempt exercises or examples during the
tutorial.
Workshop Materials
Watch this space! Please check back closer to the time for data
sets and code related to the course.
Please check here for up to date tutorial resources.
Related Links