R:如何创建基于ggplot的时间轴

问题描述 投票:0回答:1

我需要基于ggplot的时间轴。与gvisTimeline类似,但经过简化。当前无法安装更多软件包,因此我只能使用已有的软件包。

我需要在大约12小时内开始和结束可视化多个事件(大约40个)。重叠且持续时间不同。数据看起来像

Name,Start,End
event1,08/04/2020 17:45:18,08/04/2020 18:45:18 
event2,08/04/2020 20:45:18,08/04/2020 21:00:18 
event3,08/04/2020 21:00:00,09/04/2020 00:30:18 
.
.
.

谢谢:)

r ggplot2 timeline
1个回答
0
投票

我认为最简单的方法是通过破解箱形图:

ggplot(df, aes(x = Name, y = Start, fill = Name)) + 
  geom_boxplot(aes(lower = Start, ymin = Start, ymax = End, upper = End, middle = End), 
               stat = "identity", width=0.5) + 
  coord_flip()

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.