簡體   English   中英

如何以條形碼樣式進行 plot 時間序列事件

[英]how to plot timeseries events in a barcode style

如何 plot 以條形碼樣式的時間序列事件,如下面的手工示例?

條碼風格時間序列圖

對於測試,可以使用以下動物園系列:

Tdate = c("2020-04-20", "2020-04-22","2020-05-16","2020-05-29", "2020-06-20", "2020-07-02", "2020-07-18", "2020-07-19", "2020-07-22", "2020-09-14", "2020-10-10", "2020-10-15", "2020-11-22", "2020-12-22", "2020-12-24", "2020-12-25")
Tevents = data.frame(station1=c(1,0,0,1,1,1,1,0,0,0,1,1,0,1,0,1),station2=c(1,0,1,1,0,1,1,0,1,1,1,1,0,1,1,1), station3=c(0,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0) )
Zevents<-zoo(Tevents,as.Date(Tdate))

你可以:

  • pivot_longer根據station的數據
  • 使用geom_vline繪制垂直線
  • 使用facet_wrap獲取每個station的 plot
library(tidyr)
library(dplyr)
library(ggplot2)

Tevents$dat <- as.Date(Tdate)


data <- Tevents %>% pivot_longer(cols = contains('station'), names_to = 'station')

ggplot(data) + geom_point(aes(x = dat, y = 2))+
               geom_vline(aes(xintercept  = dat), data = filter(data,value == 1)) +
               coord_cartesian(ylim = c(0,1))+
               facet_wrap(~station, ncol = 1, strip.position = 'left') +
               theme(axis.title.y       = element_blank(),
                     axis.text.y        = element_blank(),
                     axis.ticks.y       = element_blank(),
                     panel.grid.minor.y = element_blank(),
                     panel.grid.major.y = element_blank())

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM