0

I am using daily time series data of 492 observations and three variables, (date, d, r). I want to print dates as 01/2020, 06/2020, 01/2021, 06/2021, 01/2022, 06/2022, on X-axis in partial and cross wavelet coherence plots. I am using this code. I am attaching the wavelets image. Thanx enter image description here

library (biwavelet)

library(readxl)

library (ggplot2)


data <- read_excel("C:\\Users\\Ahmed c zone\\Desktop\\12.xlsx")

t1 <- cbind(1:492, data$d)

t2 <- cbind(1:492, data$r)

nrand=10

sum (is.na(t1))

sum (is.na(t2))

t2[is.na(t2)]<-0

wtc.AB = wtc(t1,t2, nrands = brand)

par(oma=c(0,0,0,1), mar=c(5,4,5,5) + 0.1)

plot(wtc.AB, plot.phas=TRUE, xaxt='n', lty.coi=1, col.coi="black", 
lwd.coi=2, lwd.sig=2,arrow.lwd=0.05, arrow.len=0.08, ylab="Scale", 
xlab="Years", plot.cb=T,main="Wavelet Coherence:X vs Y")

n=length(t1 [,1])

axis(side=1, at=c(seq(0, n, 82), labels=c(seq(2020, 2022, 6))))

rm(list=ls(all=TRUE))`

Please help. I am new in using R language.

Ameer
  • 105
  • 11

1 Answers1

0

Wavelet coherence cannot be plotted directly with dates on the x-axis. However, you can create date labels and draw them along the x-axis. For this purpose, you need to use strftime function. I have run your code using randomly generated variables. Here's what you need to do

library (biwavelet)

n<-492
y1<-rnorm(n)
y2<-rnorm(n)

t1 <- cbind(1:492, y1)

t2 <- cbind(1:492, y2)

nrand<-10

wtc.AB <- wtc(t1,t2, nrands = brand)

#create a sequence of monthly dates
X <- seq(as.Date("1990/1/1"), by = "month", length.out = 492)


at<-seq(1, nrow(t1), 12*5)#set the tick marks and date labels to be 
#drawn every five years on the x-axis

#use 'strftime' function to create dates labels

labels <- strftime(as.Date(X[at], format="%F"), format ="%b %y")

#plot wavelet coherence with dates labels on the x-axis

par(oma=c(0,0,0,1), mar=c(5,4,5,5) + 0.1)

plot(wtc.AB, plot.phas=TRUE, xaxt='n', lty.coi=1, col.coi="black", 
lwd.coi=2, lwd.sig=2,arrow.lwd=0.05, arrow.len=0.08, ylab="Scale", 
xlab="Years", plot.cb=T,main="Wavelet Coherence:X vs Y")

axis(side=1, at=at, labels=labels)

Here's the results

enter image description here

Ameer
  • 105
  • 11