Search code examples
rshinyrchartsggvisgooglevis

R create interactive plot with slider which width could be changed like in Google Finance (sizeable time-window)


R create interactive plot with slider which width could be changed, example below, I'm searching in ggvis R package, but other are also welcome :

enter image description here


Solution

  • Have a look at dygraphs and dyRangeSelector().

    The dygraphs package is an R interface to the dygraphs JavaScript charting library. It provides rich facilities for charting time-series data in R

    For more information and examples, have a look at dygraph's github.io:

    install.packages("dygraphs")
    library(dygraphs)
    lungDeaths <- cbind(mdeaths, fdeaths)
    dygraph(lungDeaths) %>%
      dySeries("mdeaths", label = "Male") %>%
      dySeries("fdeaths", label = "Female") %>%
      dyOptions(stackedGraph = TRUE) %>%
      dyRangeSelector(height = 20)
    

    Which gives:

    enter image description here