Text annotations plot type

Description

Type function for adding text annotations to a plot at the specified (x,y) coordinates.

Usage

type_text(
  labels = NULL,
  adj = NULL,
  pos = NULL,
  offset = 0.5,
  family = NULL,
  font = NULL,
  vfont = NULL,
  xpd = NULL,
  srt = 0,
  clim = c(0.5, 2.5)
)

Arguments

labels Character vector of length 1 or the same length as the number of x,y coordinates. If left as NULL, then the labels will automatically inherit the corresponding y values. See Examples.
adj one or two values in \([0, 1]\) which specify the x (and optionally y) adjustment (‘justification’) of the labels, with 0 for left/bottom, 1 for right/top, and 0.5 for centered. On most devices values outside \([0, 1]\) will also work. See below.
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 (x,y) coordinates.
offset when pos is specified, this value controls the distance (‘offset’) of the text label from the specified coordinate in fractions of a character width.
family The name of a font family. Default of NULL means that the family will be the same as the main plot text, following par. Note that if a family argument is provided, then vfont (below) will automatically be ignored.
font Integer giving the font face to be used, following par. On most devices, the mapping is: 1 = regular, 2 = bold, 3 = italic, 4 = bold italic, and 5 = symbol.
vfont NULL for the current font family, or a character vector of length 2 for Hershey vector fonts. The first element of the vector selects a typeface and the second element selects a style. Ignored if labels is an expression.
xpd Logical value or NA denoting text clipping behaviour, following par.
srt Numeric giving the desired string rotation in degrees.
clim Numeric giving the lower and upper limits of the character expansion (cex) normalization for bubble charts.

Examples

library("tinyplot")

# simplest case (no labels), will auto revert to y labels
tinyplot(1:12, type = "text")

# pass explicit `labels` arg if you want specific text
tinyplot(1:12, type = "text", labels = month.abb)

# for advanced customization, it's safer to pass args through `type_text()`
tinyplot(1:12, type = type_text(
  labels = month.abb, family = "HersheyScript", srt = -20))

# same principles apply to grouped and/or facet data
tinyplot(mpg ~ hp | factor(cyl),
  data = mtcars,
  type = type_text(
    labels = row.names(mtcars),
    family = "HersheySans",
    font = 2,
    adj = 0
  )
)

# tip: use `xpd = NA` to avoid clipping text at the plot region
tinyplot(mpg ~ hp | factor(cyl),
  data = mtcars,
  type = type_text(
    labels = row.names(mtcars),
    family = "HersheySans",
    font = 2,
    adj = 0,
    xpd = NA
  )
)