fig_label: Create a label at the top left of the graphics device

View source: R/fig_label.R

fig_labelR Documentation

Create a label at the top left of the graphics device

Description

Puts a text anywhere on the device, with a logical position (such as "topleft" or "center") specified relative to one of three plotting regions (figure (default), device or plot)

Usage

fig_label(text, region = "figure", pos = "topleft", cex = NULL, ...)

Arguments

text

a character string to be plotted

region

in which region of the device the label should be placed

pos

position relative to the region ("topleft" by default)

cex

magnification of the characters. See par

...

any further parameters (e.g. col) will be passed to the text function.

Details

The main purpose of this function is to add labels (such as "A", "B", ...) to figures

Warnings

fig_label is not compatible with ggplot2. However, par(mfrow=...) and layout() work just fine.

See Also

layout, par

Examples

## Basic use:

par(mfrow=c(2,2))
for(x in LETTERS[1:4]) { 
   plot(rnorm(100))
   fig_label(x, cex=2) 
}

## Plotting at different positions and in different regions:

plot(rnorm(100))
for(i in c("topleft", "topright", "top", 
      "left", "center", "right", 
      "bottomleft", "bottom", "bottomright")) {
      fig_label(i, pos=i, cex=2, col="blue")
      fig_label(i, pos=i, cex=1.5, col="red", region="plot")
}

## All the different regions:

par(mfrow=c(2,2))
for(x in LETTERS[1:4]) { 
   plot(rnorm(100))
   fig_label("figure region", cex=2, col="red") 
   fig_label("plot region", region="plot", cex=2, col="blue")
}
fig_label("device region", cex=2, pos="bottomright", 
  col="darkgreen", region="device")

january3/myfuncs documentation built on Jan. 16, 2025, 8:37 p.m.