简体   繁体   English

绘制时间序列平滑置信区间

[英]Plot time-series smooth confident interval

I am working with this time series and I plot the smooth mean but for some reason, I cannot get the confidence area to appear.我正在处理这个时间序列并绘制平滑均值,但由于某种原因,我无法显示置信区域。 I tried using level=0.95 on the geom_smooth command but still, nothing happens.我尝试在geom_smooth命令上使用level=0.95但仍然没有任何反应。

data= https://github.com/gonzalodqa/timeseries数据= https://github.com/gonzalodqa/timeseries

months_order <- c(7:12,1:6)

dates <- make_datetime(c(rep(3,6), rep(4,6)), months_order)

t %>%
  
  mutate(datetime = make_datetime(year, month, day, hour, minute, second)) %>%

  filter(datetime >= make_datetime(2018,7), datetime < make_datetime(2020,7)) %>%
  
  group_by(year, month) %>%
  mutate(dummy = month(datetime) == 7 & datetime == min(datetime)) %>%
  ungroup() %>%
  mutate(dummy = cumsum(dummy)) %>%
  
  group_by(dummy) %>%
  mutate(datetime = datetime - years(year - 4) - years(month>=7),
         years = paste(unique(year), collapse = " / ")) %>%
  ungroup() %>%
  
  ggplot() +
  geom_line(aes(x = datetime, y = T42, colour = years)) +
  scale_x_datetime(breaks = dates, labels = month.abb[months_order]) +
  labs(colour = "Year")+geom_smooth(aes(x=datetime,y=T42),`level=0.95,color="black")+theme_light()+
  xlab("Time (Months)")+ylab("Temperature (°C)")+geom_hline(yintercept=5, linetype="dashed", color 
  = "black",lwd=1)+
  scale_color_manual(values=c("grey","grey","red"))

I have not specified any formula on geom_smooth() I tried to google the answer and also here but I cannot seem to find a solution我没有在geom_smooth()上指定任何公式我试图用谷歌搜索答案,也在这里,但我似乎找不到解决方案

Thank you for any imput感谢您的任何投入

I think it's because it's color, and it's CI is extremely narrow.我认为是因为它的颜色,而且它的 CI 非常窄。 By adding lwd = 0.5, fill = "steelblue" , I can barely find existence of CI.通过添加lwd = 0.5, fill = "steelblue" ,我几乎找不到 CI 的存在。 Take a look very carefully, then you may see something blue.仔细看看,你可能会看到蓝色的东西。

t %>%
  
  mutate(datetime = make_datetime(year, month, day, hour, minute, second)) %>%
  
  filter(datetime >= make_datetime(2018,7), datetime < make_datetime(2020,7)) %>%
  
  group_by(year, month) %>%
  mutate(dummy = month(datetime) == 7 & datetime == min(datetime)) %>%
  ungroup() %>%
  mutate(dummy = cumsum(dummy)) %>%
  
  group_by(dummy) %>%
  mutate(datetime = datetime - years(year - 4) - years(month>=7),
         years = paste(unique(year), collapse = " / ")) %>%
  ungroup() %>%
  
  ggplot() +
  geom_line(aes(x = datetime, y = T42, colour = years)) +
  scale_x_datetime(breaks = dates, labels = month.abb[months_order]) +
  labs(colour = "Year")+geom_smooth(aes(x=datetime,y=T42),level=0.95,color="black", lwd = 0.5, fill = "steelblue")+theme_light()+
  xlab("Time (Months)")+ylab("Temperature (°C)")+geom_hline(yintercept=5, linetype="dashed", color 
                                                            = "black",lwd=1)+
  scale_color_manual(values=c("grey","grey","red"))

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM