When drawing axis for time series, we usually create the tick marks and add the axis separately. Since I have to plot many time series, I tried to write the following function :
Simple plot command
set.seed(1)
x <- as.ts(rnorm(1:150))
plot <- plot(x, xaxt = "n", yaxt = "n")
Convert a set of commands from this answer into a function
tt = seq(as.Date("1994-03-01"), by="months", length=150)
tsAxis <- function (tt) {
ix <- seq_along(tt) # number of ticks
fmt <- "%b-%y" # format of time
labs <- format(tt, fmt) # names or labels of dates
axis(1, at = tt[ix], labels = labs[ix],
tcl = -0.7, cex.axis = 0.7, las = 2)
}
Then tsAxis(tt) must draw the axis but it doesnot and there is no error either. Even typing the commands separately does not plot the axis.
Any solutions?