3

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))
mindlessgreen
  • 11,059
  • 16
  • 68
  • 113
  • Just a question, Plotly is not ok for your needs? – s__ Sep 17 '18 at 13:34
  • Hmm.. Never thought of it. Not sure if plotly has a zoom slider functionality for time series. – mindlessgreen Sep 17 '18 at 13:37
  • You can try to `library(plotly)`, then wrap your `ggplot()` in a `ggplotly()`, it's a free and painless attempt, in other hands, let's wait some highcharter or dygraph ninja, I'd really like to see an answer with those packages. – s__ Sep 17 '18 at 13:42
  • Yep. `ggplotly()` is my backup plan :-) In the meantime, I will wait for the ninjas. – mindlessgreen Sep 17 '18 at 13:57
  • 1
    Maybe you can do a range bar chart usign `highcharter`. Take a look at [this page](https://www.highcharts.com/demo/columnrange). – patL Sep 20 '18 at 07:00

1 Answers1

1

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)
Koot6133
  • 1,428
  • 15
  • 26