簡體   English   中英

如何 plot 具有時間間隔數據集的觀察次數

[英]How to plot the number of observations with time intervals dataset

我有帶有 id、開始時間和結束時間的數據。

ID              start_time                end_time 
1          2017-12-29 03:52:06      2017-12-29 04:56:00
2          2017-12-29 04:12:34      2017-12-29 04:44:00
3          2017-12-29 04:24:36      2017-12-29 05:26:00
4          2017-12-29 04:30:00      2017-12-29 06:24:00
5          2017-12-29 04:33:28      2017-12-29 06:00:00
6          2017-12-29 04:52:08      2017-12-29 06:07:00
7          2017-12-29 05:13:48      2017-12-29 06:33:00
8          2017-12-29 05:33:53      2017-12-29 06:39:00
9          2017-12-29 05:40:00      2017-12-29 07:15:00
10         2017-12-29 05:30:40      2017-12-29 07:00:00
11         2017-12-29 06:08:15      2017-12-29 07:31:00
12         2017-12-29 06:12:33      2017-12-29 07:25:00 

如果我 plot 這些時間間隔,它看起來如下:

library(ggplot2)
ggplot(time_day1) + 
  aes(x = start_time, xend = end_time, y = id, yend=id, colour = id) + 
  geom_segment() + 
  geom_point() + geom_point(aes(x = end_time )) + 
  xlab("Time") + 
  theme_bw()

在此處輸入圖像描述

我想要的 plot 是與時間序列 plot 具有相同 x 軸(時間)的觀察數(id)的序列。 如果您為此提供適當的方法,我將不勝感激。

我編輯了您的帖子,以便數據中的變量與 function 匹配。

要更改 x 軸的外觀,您可以使用scale_x_datetime(date_labels = "%d.%m.%Y") 在這種情況下,列 start_time/first_time 和 end_time/last_time 必須是 class POSIXct

要了解有關它的更多信息,請參閱R 圖形庫tidyverse/ggplot2包的官方參考。

暫無
暫無

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

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