R中的多个ggAcf图 [英] Multiple ggAcf plot in R

查看:215
本文介绍了R中的多个ggAcf图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个时间序列数据,我想在一个具有不同颜色的ggplot中绘制ACF,我刚刚找到了ggAcf,但无法解决我的问题

I have 2 time series data and I want to plot the ACF in one ggplot with different colour, I just found ggAcf, but it couldn't solve my problem

library(ggplot2)
data1<-seq(1,300,3)
data2<-seq(1,100,0.5)
ggAcf(data2,1)
ggAcf(data2,20)

我想按照以下类型绘制剧情

I want to make the plot as follow type

我该如何解决?

推荐答案

library(ggplot2)
library(reshape2)
data1 <- seq(1, 300, 3)
data2 <- seq(1, 100, 0.5)
acf1 <- acf(data1, plot = F, lag.max = 25)
acf2 <- acf(data2, plot = F, lag.max = 25)
df<- data.frame(lag = acf1$lag,acf1=acf1$acf,acf2=acf2$acf)
colnames(df)<-c("lag","data1","data2")
data<-melt(df,id="lag")
ggplot(data, aes(x=lag, y=value)) +
   geom_area(aes(colour = variable, fill= variable), position = 'stack') 

这篇关于R中的多个ggAcf图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆