figureCaption: Add a caption to a lattice or ggplot2 object

View source: R/figureCaption.R

figureCaptionR Documentation

Add a caption to a lattice or ggplot2 object

Description

this function adds a caption to an existing plot object (either lattice or ggplot2). strwrap is used to automatically wrap text at column 75. Clipping is off, so long text will continue downward outside the plotting region. Keep this in mind when setting the height of your graphics device.

Usage

figureCaption(obj, txt, width = 75L, ...)

Arguments

obj

the lattice or ggplot2 object to which the caption should be added

txt

the cpation text

width

target column for wrapping lines, see strwrap

...

additional parameters passed on to gpar. These can be used to adjust the fontsize, fontfamily etc. Note that the default value for fontsize is 16 pt.

Author(s)

Tim Appelhans

Examples

## lattice example
library(lattice)

p1 <- levelplot(volcano)
txt <- "Fig 1.: Elevation of Maunga Whau (Mt Eden) volcano in Auckland. 
Axes are standardised values."

figureCaption(p1, txt)

## change font size
figureCaption(p1, txt, fontsize = 12)

## ggplot2 example
library(ggplot2)

p2 <- qplot(1:10, rnorm(10), colour = runif(10))
figureCaption(p2, "Fig. 2: Some color coded random numbers.", 
              fontface = "italic")


environmentalinformatics-marburg/Rsenal documentation built on July 28, 2023, 6:09 a.m.