Learn R Programming

tinyplot (version 0.8.0)

tinyAxis: Generic function for adding an axis to a (tiny)plot

Description

Internal function used for adding an axis to a tinyplot call.

Usage

tinyAxis(
  x = NULL,
  ...,
  type = "standard",
  labeller = NULL,
  srt = NULL,
  hang = FALSE
)

Arguments

x

an object which indicates the range over which an axis should be drawn

...

arguments to be passed to methods and perhaps then to axis.

type

the type of axis to be drawn; inherited from the xaxt or yaxt arguments of the parent tinyplot() call. One of either: "standard" (default that draws the axis, ticks, and labels), "none" (no axes), "ticks" (only ticks and labels without axis line), "labels" (only labels without ticks and axis line), or "axis" (only axis line and labels but no ticks). Partial matching is allowed, e.g. type = "s".

labeller

how the labels should be relabelled or reformatted. One of:

  • a function to be applied to x, e.g. format, toupper, abs, or any other custom function (including from the popular scales package).

  • one of the following convenience strings (or their symbol equivalents), for which common formatting transformations are provided: "percent" ("%"), "comma" (","), "log" ("l"), "dollar" ("$"), "euro" ("€"), or "sterling" ("£").

  • a dictionary, i.e. a named character vector or list of form c(old_lab = "new_lab", ...). Entries of x that match a name are replaced by the corresponding value and the rest are left alone, so a partial mapping is fine. The lookup is by value rather than by position, which means it is unaffected by any reordering of the underlying categories.

Note that an unnamed character vector of length greater than one is an error, rather than a positional replacement of the labels. Such a vector cannot be distinguished from a formatting keyword when x is of length one, and would not follow the categories if they were reordered. Pass a function if you want to compute the labels positionally, e.g. function(x) LETTERS[seq_along(x)].

srt

numeric giving the tick label rotation in degrees counter-clockwise, or NULL (default) to leave the labels to base axis() and its las setting. Any non-zero value is drawn by hand, since axis() only understands the four right angles that las selects.

hang

logical. If TRUE, multi-line side-1 tick labels (under las 0 or 1) hang down from their first line, rather than growing upwards into the ticks as base axis() does. Used by dynmar themes, which reserve margin space for the extra lines.

Details

tinyAxis provides a thin(ish) wrapper around Axis, but with enhanced flexibility to (i) match parameter combinations based on the axis type and plotting theme, (ii) provide better support for date-time variables, and (iii) enable convenient formatting of axis tick labels.

Examples

Run this code
if (FALSE) {

# plot without axes
tinyplot(0:10, axes = "n")
# add x-axis (labels only)
tinyplot:::tinyAxis(x = 0:10, side = 1, type = "l")
# add y-axis (with custom label formatting)
tinyplot:::tinyAxis(x = 0:10, side = 2, type = "s", labeller = "$")
}

Run the code above in your browser using DataLab