I have conducted a wavelet analysis on an hourly time series and am trying to plot the output. To conduct the analysis, I had to convert the POSIXct date & time stamp (e.g., 2020-06-20 14:00) to a continuous sequence of 1,2,3...
I know how to make the plot in base R, but I cannot figure out how to convert from the continuous sequence back to the original date & time stamp. Any ideas on how to do this?
Example Data:
set.seed(321)
dat <- as.data.frame(matrix(nrow = 20222, ncol = 2))
colnames(dat)[1:2] <- c('datetime','value')
dat$datetime <- seq(as.POSIXct('2020-06-20 00:00', tz = "America/Jamaica", "%Y-%m-%d %H:%M"),
by = 'hour',
length.out = 20222)
x = seq(1,20222,2*pi/6.2832)
y1 = sin(x/1250) + 20
y2 = rnorm(n = 20222, mean = 0, sd = 0.3)
dat$value = y1 + y2
plot(dat)
Plotting the analysis output:
library(biwavelet)
# this throws an error which I believe is due to biwavelet not
# working with class POSIXct
test <- wt(dat)
# because of the error above, I replace the date time with
# a numerical sequence
dat$datetime <- seq(1,NROW(dat),1)
# conducts the wavelet transform analysis
test <- wt(dat)
# displays the wavelet transform analysis output
plot(test,
plot.cb = F, plot.phase = F, plot.sig = F,
alpha.coi = 0.7,
col.coi = 'black',
cex.axis = 1.5,
cex.lab = 1.5)
Again, I would like the x-axis to be the date rather than the continuous sequence. I think this can be done with the form =
command inside of plot.biwavelet()
but it is unclear to me how that works from the biwavelet
documentation.