R语言绘图:时间序列分析 ggplot2绘制ACF PACF

R语言真是博大精深

方法一

Acf(gold[,2], type = "correlation",lag.max = 100)
Acf(gold[,2], type = "partial")

方法二

library(ggfortify)
autoplot(acf(gold[,2], plot = FALSE))

方法三

bacf <- acf(gold[, 2], plot = FALSE)
bacfdf <- with(bacf, data.frame(lag, acf))
ggplot(data = bacfdf, mapping = aes(x = lag, y = acf)) +
    geom_segment(mapping = aes(xend = lag, yend = 0)) +
    geom_hline(aes(yintercept = 0.05), linetype = 2, color = 'darkblue')
# pacf
bpacf <- pacf(gold[, 2], plot = FALSE)
bpacf <- with(bpacf, data.frame(lag, acf))
ggplot(data = bpacf, mapping = aes(x = lag, y = acf)) +
    geom_segment(mapping = aes(xend = lag, yend = 0)) +
    geom_hline(aes(yintercept = 0.05), linetype = 2, color = 'darkblue')

方法四

library("forecast")
forecast::ggtsdisplay(gold[,2],lag.max=30)

方法五

ggAcf(gold[,2])
ggPacf(gold[,2])
posted @ 2017-12-26 14:46  嘻呵呵  阅读(6641)  评论(0编辑  收藏  举报