-1

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.

Ahmed Arif
  • 189
  • 1
  • 2
  • 10
  • Can you put together a reproducible example? We don't have `data.dta`. You don't need to include real data, just generate some fake data that shows the same problem you're seeing. – user2554330 Jun 12 '21 at 13:23
  • @user2554330 question edited and data is also included in the question. – Ahmed Arif Jun 12 '21 at 14:35

1 Answers1

1

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

user2554330
  • 37,248
  • 4
  • 43
  • 90
  • Thank you for your response. However, this does not work if the date is not continuous like in the case of the stock market when data is not observed daily but 5 days a week. The error appears as: `Error in check.datum(d) : The step size must be constant (see approx function to interpolate)` – Ahmed Arif Jun 17 '21 at 12:20
  • @AhmedArif: That seems like a different issue. Could you put together an example, and post it as a new question? – user2554330 Jun 18 '21 at 10:18
  • I posted a new question as you said here. Can you please answer this question? https://stackoverflow.com/questions/68190641/date-with-gaps-wavelet-analysis-in-r-using-biwavelet-package – Ahmed Arif Jun 30 '21 at 07:56