微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 plot.ts 在 x-avis 上添加日期而不是数值

如何解决使用 plot.ts 在 x-avis 上添加日期而不是数值

我正在 R 中编写一个脚本,我必须在其中绘制存储在矩阵中的三个估计模型作为时间图。 我使用“quantmod”包从雅虎财经中提取数据,此后创建了一个包含这些数据日期的向量,称为 vDates。

现在我想根据向量中包含的日期绘制模型的估计值。他们有

plot.ts(mSigma_DJI,plot.type = "single",col = c("green","black","blue"),main = "Filtered volatilities for Dow Jones",xlab = "Time",ylab = expression(paste(sigma[t]^2)))

我以如下方式提取了数据:

library(quantmod)

# Reading the series for DJI and S&P500:
vSP500 = getSymbols("^GSPC",from = "2007-01-03",to = "2019-01-01",auto.assign = FALSE)

vDJI = getSymbols("^DJI",auto.assign = FALSE)

# Extracting the dates of the series to use in plots:
vDates = as.Date(row.names(as.matrix(vDJI)))[-1]

# Creating the series with the percentage logarithmic returns of both series
vSP500 = diff(log(as.numeric(vSP500$GSPC.Adjusted))) * 100
vDJI = diff(log(as.numeric(vDJI$DJI.Adjusted))) * 100

.
.
.

# Then the estimated values are save here:
mSigma_SP500[,"GARCH"] = GARCH_Fit_SP500$vSigma

但是情节看起来就像在附图中看到的那样。我希望将包含日期 vDates 的向量作为 x-avis,而不是绘图上的 x-avis。似乎我无法使用“xts”包来做到这一点。

Plot with numerical values on x-axis

有什么关于如何做到这一点的建议吗?

提前致谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。