r ggplot时间序列,方面,黄土和日期

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了r ggplot时间序列,方面,黄土和日期相关的知识,希望对你有一定的参考价值。

# from Lubrizol NOV 2017
# written by Andy L

# P12 2016 Priority 0 fails
# ~~~~~~~~~~~~~~~~~~~~~~~~~
p_E12_2016 <- viz_df %>%
  
  filter(
    
    time_stamp_h > ymd("2016-01-01") & time_stamp_h < ymd("2016-12-31"),

    !measure %in% c(
      #"Process Flow", 
      "Process Temp",
      #"Pump Speed",
      "Process Pressure"
      #"Pump Speed"
      #"Pump")
    )
  )%>% 
  
  ggplot() +
  geom_line(aes(x = time_stamp_h, y = value)) +
  facet_grid(measure ~ functional_location, scales = "free") +
  
  # vertical red line for failures
  geom_vline(xintercept = as.numeric(as.POSIXct("2016-01-22 12:00:00")),  color = "red", size =  1.3) +
  geom_vline(xintercept = as.numeric(as.POSIXct("2016-05-06 12:00:00")),  color = "red",  size = 1.3) +
  geom_vline(xintercept = as.numeric(as.POSIXct("2016-10-10 12:00:00")),  color = "red",  size = 1.3)
  
  # ~~~~~~~~~~~
  # example with loess smoothing
  # ~~~~~~~~~~~
  
  # 2016 Fail 1 short
# ~~~~~~~~~~~~~~~~~
pre_days <- 10
post_days <- 5
f_date <-  ymd_hms("2016-10-10 12:00:00")
f_min <- f_date - days(pre_days)
f_max <- f_date + days(post_days)

p_E12_f1_2016s <- viz_df %>%
  
  filter(
    
    time_stamp_h > f_min & time_stamp_h < f_max,
    
    !measure %in% c(
      #"Process Flow", 
      "Process Temp",
      "Process Pressure"
      #"Process Flow",
      #"Pump Speed"
      #"Pump Speed"
    )
    
  ) %>% 
  
  ggplot(aes(x = time_stamp_h, y = value)) +
  geom_line() +
  
  # loess line - NOTE: aes must be in ggplot() NOT in geom_line()
  geom_smooth(span = 0.15) +
  
  facet_grid(measure ~ functional_location, scales = "free") +
  
  # vertical red line for failures
  geom_vline(xintercept = as.numeric(as.POSIXct("2016-01-22 12:00:00")),  color = "red", size =  1.3) +
  geom_vline(xintercept = as.numeric(as.POSIXct("2016-05-06 12:00:00")),  color = "red",  size = 1.3) +
  geom_vline(xintercept = as.numeric(as.POSIXct("2016-10-10 12:00:00")),  color = "red",  size = 1.3)
  
  # use facet_wrap
  # facet by lines
ggplot(data = repairs, aes(x = ttf)) +
  theme_bw() +
  geom_histogram(stat = "bin", bins = 40, aes(fill = line)) +
  facet_wrap(~ line, nrow = 2) + 
  labs(
    title = "Distribution of time to failure", 
    x = "time to failure",
    y = "# of failures" )

以上是关于r ggplot时间序列,方面,黄土和日期的主要内容,如果未能解决你的问题,请参考以下文章

ggplot2使用单独的日期和可变数据帧按日期绘制时间序列r

如何使用 R 在校准图中添加黄土线、斜率和截距?

如何快速(优雅地)在 R 中的时间序列对象 `ts` 和日期框架之间进行迭代以进行 ggplot2 绘图?

为啥我的多元回归的 95% 置信区间被绘制为黄土线?

R语言ggplot2时间序列可视化并在特定日期处添加竖线实战

ggplot 标签水平线出现在 2 个方面(x 轴是日期,中间部分已删除)