Add a nicely formatted x-axis to time series plots related to the "sts" class. This utility function is, e.g., used by stsplot_time1 and plotHHH4_fitted1.

## Usage

addFormattedXAxis(x, epochsAsDate = FALSE,
xaxis.tickFreq = list("%Q"=atChange),
xaxis.labelFreq = xaxis.tickFreq,
xaxis.labelFormat = "%G\n\n%OQ",
...)

## Arguments

x

an object of class "sts".

epochsAsDate

a logical indicating if the old (FALSE) or the new (TRUE) and more flexible implementation should be used. The xaxis.* arguments are only relevant for the new implementation epochsAsDate = TRUE.

xaxis.labelFormat,xaxis.tickFreq,xaxis.labelFreq

see the details below.

...

further arguments passed to axis.

## Details

The setting epochsAsDate = TRUE enables very flexible formatting of the x-axis and its annotations using the xaxis.tickFreq, xaxis.labelFreq and xaxis.labelFormat arguments. The first two are named lists containing pairs with the name being a strftime single conversion specification and the second part is a function which based on this conversion returns a subset of the rows in the sts objects. The subsetting function has the following header: function(x,xm1), where x is a vector containing the result of applying the conversion in name to the epochs of the sts object and xm1 is the scalar result when applying the conversion to the natural element just before the first epoch. Please note that the input to the subsetting function is converted using as.numeric before calling the function. Hence, the conversion specification needs to result in a string convertible to integer.

Three predefined subsetting functions exist: atChange, at2ndChange and atMedian, which are used to make a tick at each (each 2nd for at2ndChange) change and at the median index computed on all having the same value, respectively:


atChange <- function(x,xm1) which(diff(c(xm1,x)) != 0)
at2ndChange <- function(x,xm1) which(diff(c(xm1,x) %/% 2) != 0)
atMedian <- function(x,xm1) tapply(seq_along(x), INDEX=x, quantile, prob=0.5, type=3)


By defining own functions here, one can obtain an arbitrary degree of flexibility.

Finally, xaxis.labelFormat is a strftime compatible formatting string., e.g. the default value is "%G\n\n%OQ", which means ISO year and quarter (in roman letters) stacked on top of each other.

## Value

NULL (invisibly). The function is called for its side effects.

## Author

Michael Höhle with contributions by Sebastian Meyer

the examples in stsplot_time1 and plotHHH4_fitted1