我正在使用由谷歌员工开发的CausalImpact包来评估干预在一段时间序列中的因果影响。
See the documentation for more info。
我创建了一个图,如示例中所示。我想添加一个图例,就像我们在第249页找到的here一样。
我知道使用( CausalImpact包的)函数图会产生一个ggplot2对象。但是,我不知道如何添加图例。
一些可重现的数据:
library(devtools)
devtools::install_github("google/CausalImpact")
library(CausalImpact)
set.seed(1)
x1 <- 100 + arima.sim(model = list(ar = 0.999), n = 100)
y <- 1.2 * x1 + rnorm(100)
y[71:100] <- y[71:100] + 10
data <- cbind(y, x1)
pre.period <- as.Date(c("2014-01-01", "2014-03-11"))
post.period <- as.Date(c("2014-03-12", "2014-04-10"))
time.points <- seq.Date(as.Date("2014-01-01"), by = 1, length.out = 100)
data <- zoo(cbind(y, x1), time.points)
impact <- CausalImpact(data, pre.period, post.period)
plot(impact)发布于 2015-09-14 16:47:49
发布于 2018-03-22 22:27:08
或者,您也可以使用impact[["series"]]中的数据创建自己的图
https://stackoverflow.com/questions/32529517
复制相似问题