自相关的 ggplot 问题,一个 line/variable 在滞后 0 时不缩放到 1。但数据显示它的相关性在滞后 0 时为 1

ggplot problem with autocorrelation, one line/variable doesnt scale to 1 at lag 0. But the data shows that it's correlation is 1 at lag 0

我使用的代码:

p11 <- ggplot(Autokor)+
  geom_line(aes(x=Lag, y=0))+
  stat_smooth(aes(y=Kryds_HP_HP, x=Lag, color = "HUSPRIS"), formula = y ~ s(x, k = 11), method = "gam", se = FALSE) +
  stat_smooth(aes(y=Kryds_RENTE_RENTE, x=Lag, color = "RENTE"), formula = y ~ s(x, k = 11), method = "gam", se = FALSE) +   
  stat_smooth(aes(y=Kryds_BNP_BNP, x=Lag, color = "BNP"), formula = y ~ s(x, k = 11), method = "gam", se = FALSE) +
  stat_smooth(aes(y=Kryds_KREDIT_KREDIT, x=Lag, color = "KREDIT"), formula = y ~ s(x, k = 11), method = "gam", se = FALSE) +
  scale_y_continuous(labels = function(x) format(x, big.mark = ".", decimal.mark = ",") ,limits = c(-1, 1), breaks=round(seq(min(-1), max(1), by = 0.5),1)) +
  scale_x_continuous(labels = function(x) format(x, big.mark = ".", decimal.mark = ",") ,limits = c(-6, 6), breaks=round(seq(min(-6), max(6), by = 1),1)) +
  labs(title = "Autokorrelationer", x="Lag", y="Korrelation", caption = "", color=NULL)+ theme(legend.position="bottom") + theme(panel.grid.minor.x = element_blank()) + th

我的问题是这些值显示红线 (BNP) 应该在相关值 1、滞后 0 处有一个顶部,但在 ggplot BNP 顶部接近 0.4

The new autocorrelation plot

p11 <- ggplot(Autokor)+ geom_line(aes(x=Lag, y=0))+ geom_line(aes(y=Kryds_HP_HP, x=Lag, color = "HUSPRIS"), formula = y ~ s(x, k = 11), method = "gam", se = FALSE) + geom_line(aes(y=Kryds_RENTE_RENTE, x=Lag, color = "RENTE"), formula = y ~ s(x, k = 11), method = "gam", se = FALSE) + geom_line(aes(y=Kryds_BNP_BNP, x=Lag, color = "BNP"), formula = y ~ s(x, k = 11), method = "gam", se = FALSE) + geom_line(aes(y=Kryds_KREDIT_KREDIT, x=Lag, color = "KREDIT"), formula = y ~ s(x, k = 11), method = "gam", se = FALSE) + scale_y_continuous(labels = function(x) format(x, big.mark = ".", decimal.mark = ",") ,limits = c(-1, 1), breaks=round(seq(min(-1), max(1), by = 0.5),1)) + scale_x_continuous(labels = function(x) format(x, big.mark = ".", decimal.mark = ",") ,limits = c(-6, 6), breaks=round(seq(min(-6), max(6), by = 1),1)) + labs(title = "Autokorrelationer", x="Lag", y="Korrelation", caption = "", color=NULL) + theme(legend.position="bottom") + theme(panel.grid.minor.x = element_blank()) + th

问题是 stat_smooth() 在滞后 0 时过于激进地接近 1。因此通过将 stat_smooth() 替换为 geom_line().

解决了这个问题