FigRs' Bag of Tricks

Here are some simple tricks that help with bringing R graphics into a collaborative process. The Downloads page has a reference sheet summarizing the R functions and options used in the various FigRs.

Print to pdf slides - R figures can be printed straight to a multi-page pdf file with the same dimensions as powerpoint slides. Once set up, this allows you to create hi-res presentations on the fly, for example in response to a request for changing one of the inputs in a simulation model. It also works for creating simple animations based on the same principle as the old flip-books. These pseudo-animations work on all browsers and operating systems, and are easy to share with end users (small file size, high resolution, common file type).

pdf("SampleSlides.pdf",width=11, height=8.5,onefile=TRUE)
# insert all your plotting code here # close the plotting device

layout() - Divides the screen or pdf page (i.e. the active plotting device) into smaller panels. You can specify different heights and widths for the panels, plot figures that span multiple panels, and determine the order in which the panels are filled.

mat <- matrix(c(1,3,2,3), byrow=TRUE, nrow=2)
layout(mat, heights=c(2,1), widths=c(1,2)) # check the 3 panels

xpd = TRUE or NA - Expands a plotting area beyond its current boundaries. This lets you run point labels into the margins (xpd=TRUE) or visually connect two points in different panels (xpd=NA). For example, if you have two panels with the same range of years on the horizontal axis, then abline(v=c(1980, 1990, 2000, 2010), xpd=NA) will add lines across both panels to emphasize the start of each decade.

The following templates illustrate all 3 of these tricks combined: