Skip to contents

Compute x-axis tickmarks like axTicks() in base but with respect to time. This function is written for internal use, and documented for those wishing to use it for customized plots.

Usage

axTicksByTime(
  x,
  ticks.on = "auto",
  k = 1,
  labels = TRUE,
  format.labels = TRUE,
  ends = TRUE,
  gt = 2,
  lt = 30
)

Arguments

x

An object indexed by time or a vector of times/dates.

ticks.on

Time unit for tick locations.

k

Frequency of tick locations.

labels

Should a labeled vector be returned?

format.labels

Either a logical value specifying whether labels should be formatted, or a character string specifying the format to use.

ends

Should the ends be adjusted?

gt

Lower bound on number of tick locations.

lt

Upper bound on number of tick locations.

Value

A numeric vector of index element locations where tick marks should be drawn. These are locations (e.g. 1, 2, 3, ...), not the index timestamps.

If possible, the result will be named using formatted values from the index timestamps. The names will be used for the tick mark labels.

Details

The default ticks.on = "auto" uses heuristics to compute sensible tick locations. Use a combination of ticks.on and k to create tick locations at specific intervals. For example, ticks.on = "days" and k = 7 will create tick marks every 7 days.

When format.labels is a character string the possible values are the same as those listed in the Details section of strptime().

See also

Author

Jeffrey A. Ryan

Examples


data(sample_matrix)
axTicksByTime(as.xts(sample_matrix),'auto')
#> Jan 02\n2007 Jan 08\n2007 Jan 15\n2007 Jan 22\n2007 Jan 29\n2007 Feb 05\n2007 
#>            1            7           14           21           28           35 
#> Feb 12\n2007 Feb 19\n2007 Feb 26\n2007 Mar 05\n2007 Mar 12\n2007 Mar 19\n2007 
#>           42           49           56           63           70           77 
#> Mar 26\n2007 Apr 02\n2007 Apr 09\n2007 Apr 16\n2007 Apr 23\n2007 Apr 30\n2007 
#>           84           91           98          105          112          119 
#> May 07\n2007 May 14\n2007 May 21\n2007 May 28\n2007 Jun 04\n2007 Jun 11\n2007 
#>          126          133          140          147          154          161 
#> Jun 18\n2007 Jun 25\n2007 Jun 30\n2007 
#>          168          175          180 
axTicksByTime(as.xts(sample_matrix),'weeks')
#> Jan 02\n2007 Jan 08\n2007 Jan 15\n2007 Jan 22\n2007 Jan 29\n2007 Feb 05\n2007 
#>            1            7           14           21           28           35 
#> Feb 12\n2007 Feb 19\n2007 Feb 26\n2007 Mar 05\n2007 Mar 12\n2007 Mar 19\n2007 
#>           42           49           56           63           70           77 
#> Mar 26\n2007 Apr 02\n2007 Apr 09\n2007 Apr 16\n2007 Apr 23\n2007 Apr 30\n2007 
#>           84           91           98          105          112          119 
#> May 07\n2007 May 14\n2007 May 21\n2007 May 28\n2007 Jun 04\n2007 Jun 11\n2007 
#>          126          133          140          147          154          161 
#> Jun 18\n2007 Jun 25\n2007 Jun 30\n2007 
#>          168          175          180 
axTicksByTime(as.xts(sample_matrix),'months',7)
#> Jan 02\n2007 Jun 30\n2007 
#>            1          180