axis_t: Compute Time Axis Parameters for Plotting

axis_tR Documentation

Compute Time Axis Parameters for Plotting

Description

Auxiliary function axis_t returns a six-element list with axis limits (in Cartesian coordinates), tick-mark positions (in Cartesian coordinates), tick-mark labels (character vector), positioning of minor tick-marks (in Cartesian coordinates), resolution of indices (in Cartesian coordinates), and limits argument converted to a tinterval of the same index type as x. The results can be used for manual creation of axes in plots.

Usage

axis_t(
  x,
  limits = NULL,
  format = NULL,
  locale = NULL,
  expand = FALSE,
  n.breaks = 5L
)

Arguments

x

time indices for which an axis is to be created.

limits

NULL for automatic limits, tinterval of length 1 or tind of length 2.

format

(optional) a character string determining label format (see format) or a custom formatting function.

locale

(optional) a character string determining locale to be used for formatting labels, see calendar-names for information on locale settings.

expand

a logical value. If TRUE, limits are expanded by 3% on both sides.

n.breaks

an integer value, desired number of breaks.

Value

A six-element list with scale limits (lim), vector of tick-mark positions (at), character vector with tick-mark labels (labels), vector of minor tick-mark positions (minor), resolution (in Cartesian coordinates) of time indices (resolution), and limits argument converted to a tinterval of the same index type as x (limits).

See Also

pretty for computing pretty breakpoints, axis.tind for creating axes with graphics package, scale_tind for creating axes with ggplot2.

Examples


# load graphics
library(graphics)
# artificial data
N <- 180
df <- data.frame(d = today() + (-N + 1):0, y = cumsum(rnorm(N)))
(axt <- axis_t(df$d, format = "%m/%d/%y", n.breaks = 6L))
# custom time axis with minor breaks
plot(df$d, df$y, xlim = axt$lim, type = "l", xaxt = "n", xaxs = "i")
axis(1, at = axt$lim, labels = FALSE, lwd = 1, lwd.ticks = 0)
axis(1, at = axt$at, labels = axt$labels, lwd = 0, lwd.ticks = .7)
axis(1, at = axt$minor, labels = FALSE, lwd = 0, lwd.ticks = .4)



tind documentation built on Dec. 28, 2025, 1:06 a.m.