FunBoxtext: Add text with background box to a plot

View source: R/FunBoxtext.R

FunBoxtextR Documentation

Add text with background box to a plot

Description

boxtext places a text given in the vector labels onto a plot in the base graphics system and places a coloured box behind it to make it stand out from the background.

Usage

FunBoxtext(
  x,
  y,
  labels = NA,
  col.text = NULL,
  col.bg = NA,
  border.bg = NA,
  adj = NULL,
  pos = NULL,
  offset = 0.5,
  padding = c(0.5, 0.5),
  cex = 1,
  font = graphics::par("font")
)

Arguments

x

numeric vector of x-coordinates where the text labels should be written. If the length of x and y differs, the shorter one is recycled.

y

numeric vector of y-coordinates where the text labels should be written.

labels

a character vector specifying the text to be written.

col.text

the colour of the text

col.bg

color(s) to fill or shade the rectangle(s) with. The default NA means do not fill, i.e., draw transparent rectangles.

border.bg

color(s) for rectangle border(s). The default NA omits borders.

adj

one or two values in 0, 1 which specify the x (and optionally y) adjustment of the labels.

pos

a position specifier for the text. If specified this overrides any adj value given. Values of 1, 2, 3 and 4, respectively indicate positions below, to the left of, above and to the right of the specified coordinates.

offset

when pos is specified, this value gives the offset of the label from the specified coordinate in fractions of a character width.

padding

factor used for the padding of the box around the text. Padding is specified in fractions of a character width. If a vector of length two is specified then different factors are used for the padding in x- and y-direction.

cex

numeric character expansion factor; multiplied by codepar("cex") yields the final character size.

font

the font to be used

Value

Returns the coordinates of the background rectangle(s). If multiple labels are placed in a vactor then the coordinates are returned as a matrix with columns corresponding to xleft, xright, ybottom, ytop. If just one label is placed, the coordinates are returned as a vector.

Author(s)

Ian Kopacka

Examples

## Create noisy background
plot(x = runif(1000), y = runif(1000), type = "p", pch = 16,
col = "#40404060")
boxtext(x = 0.5, y = 0.5, labels = "some Text", col.bg = "#b2f4f480",
    pos = 4, font = 2, cex = 1.3, padding = 1)

retodomax/FunRZ documentation built on Sept. 4, 2024, 9:56 a.m.