Search code examples
rggplot2timeline

R: How to create ggplot based timeline


I need ggplot based timeline. Something similar to gvisTimeline but simplified. Currently there is no way to install more packages, so I am limited to what I already have.

I need to visualize multiple events (around 40) with start and end in around 12 hours. Overlapping and with different duration. The data looks like

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 
.
.
.

Thank you :)


Solution

  • I think the easiest way to do this is by hacking a boxplot:

    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