小波中的X轴日期

发布于 2025-01-23 21:39:28 字数 926 浏览 7 评论 0原文

我使用的是492个观测值和三个变量(日期,d,r)的每日时间序列数据。我想打印日期为01/2020,06/2020,01/2021,06/2021,01/2022,06/2022,在X-axis中,部分和交叉小波相干图。我正在使用此代码。我正在附上小波图像。 thanx 在此处输入图像描述

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))`

请帮助。我是使用R语言的新手。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空名 2025-01-30 21:39:28

小波相干性不能直接用X轴上的日期绘制。但是,您可以创建日期标签并沿X轴绘制它们。为此,您需要使用strftime函数。我已经使用随机生成的变量来运行您的代码。这是您需要做的,

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)

这是结果

”在此处输入图像说明”

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文