Interactive duration plot

123 Views Asked by At

I have samples and duration.

library(lubridate)
daf <- data.frame(sample=c("m","k","c","b"),duration=ddays(c(4,2,1,3)))
daf$start <- Sys.time()-daf$duration

> head(daf)
  sample          duration               start
1      m 345600s (~4 days) 2018-09-13 15:08:17
2      k 172800s (~2 days) 2018-09-15 15:08:17
3      c  86400s (~1 days) 2018-09-16 15:08:17
4      b 259200s (~3 days) 2018-09-14 15:08:17

I've been able to plot this using ggplot and looks like below.

library(ggplot2)
ggplot(daf)+
geom_segment(aes(x=start,y=sample,xend=Sys.time(),yend=sample))+
 theme_minimal()

enter image description here

I would like to have this as an interactive plot using dygraphs or highcharter. Especially to use the interactive zoom slider and additional variables as tooltips. But, I am not sure how to get this data to work with dygraphs or highcharter.

library(xts)
library(dygraphs)
dygraph(xts(as.integer(factor(daf$sample)),order.by=daf$start))
library(highcharter)
hchart(xts(as.integer(factor(daf$sample)),order.by=daf$start))
1

There are 1 best solutions below

0
On

You might want to try the library timevis, which is made for visualizing timelines.

daf <- data.frame(content=c("m","k","c","b"),duration=ddays(c(4,2,1,3)))
daf$start <- Sys.time()-daf$duration
daf$end <- Sys.time()
timevis(daf)