rdatetime-serieswavelet-transform

Continuous Wavelet Transform - Date Not Shown in Proper Format


I am performing a Wavelet Analysis using the "biwavelet" package in R. I am running the following code:

   library(foreign)
   library(survey)
   library(dplyr)
   library(Rwave)
   library(waveslim)
   library(biwavelet)
   library(xts)
   library(labelled)
   library(zoo)
   
   date =c("2020-02-13", "2020-02-14", "2020-02-15", "2020-02-16", "2020-02-17", "2020-02-18", "2020-02-19", "2020-02-20", "2020-02-21", "2020-02-22", "2020-02-23", "2020-02-24", "2020-02-25", "2020-02-26", "2020-02-27", "2020-02-28", "2020-02-29", "2020-03-01", "2020-03-02", "2020-03-03", "2020-03-04", "2020-03-05", "2020-03-06", "2020-03-07", "2020-03-08", "2020-03-09", "2020-03-10", "2020-03-11", "2020-03-12", "2020-03-13")
   rdate = as.Date(date)
   date <- as.Date(date, format = "%Y-%m-%d")
   date
   class(date)
   var = c(-0.032297026, -0.037759505, -0.043272924, -0.048837278, -0.054452576, -0.060118809, -0.065835983, -0.071604095, -0.077423148, -0.083293147, -0.089214072, -0.095185943, -0.101208754, -0.107282504, -0.113407195, -0.119582824, -0.125809386, -0.125806898, -0.132149309, -0.138584509,  -0.145112529, -0.151733354, -0.158446968, -0.165253401, -0.172152638, -0.179144681, -0.186229542, -0.193407193, -0.200677648, -0.208040923)
     data = data.frame(date, var)
     View(data)
     X <- as.xts(data[,-1], order.by = date)
     attach(data)
     ABC <- cbind(date, var)
     wt.t1=plot(wt(ABC))

The generated plot does not show the date in the proper format, rather it appears like 18305, 18310 etc. How I can show the date in the proper date format.


Solution

  • The problem is the second last line of your script: ABC <- cbind(date, var). The cbind() function outputs a matrix, and you can't have a separate class for the two columns. If you use ABC <- data.frame(date, var) the Date class won't be lost.

    The picture still doesn't look great, though, because the default format is "%Y", so all the dates are displayed the same, as "2020". To get a better plot, pick a date format and use that, e.g.

    plot(wt(ABC), form = "%b-%d")
    

    which gives

    screenshot