- Automatically plots xts time-series objects (or objects convertible to xts).
- Rich interactive features including zoom/pan and series/point highlighting.
- Highly configurable axis and series display (including optional 2nd Y-axis).
- Display upper/lower bars (e.g. prediction intervals) around series.
- Various graph overlays including shaded regions, event lines, and annotations.
- Use at the R console just like conventional R plots (via RStudio Viewer).
- Embeddable within R Markdown documents and Shiny web applications.
The dygraphs package is available on CRAN now and can be installed with:
Here are some examples of interactive time series visualizations you can create with only a line or two of R code (the screenshots are static, click them to see the interactive version).
Panning and Zooming
This code adds a range selector that’s can be used to pan and zoom around the series data:
dygraph(nhtemp, main = "New Haven Temperatures") %>% dyRangeSelector()
When you hover over the time-series the values of all points at the location of the mouse are shown in the legend:
lungDeaths <- cbind(ldeaths, mdeaths, fdeaths) dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>% dyOptions(colors = RColorBrewer::brewer.pal(3, "Set2"))
Shading and Annotations
There are a wide variety of tools available to annotate time series. Here we demonstrate creating shaded regions:
dygraph(nhtemp, main="New Haven Temperatures") %>% dySeries(label="Temp (F)", color="black") %>% dyShading(from="1920-1-1", to="1930-1-1", color="#FFE6E6") %>% dyShading(from="1940-1-1", to="1950-1-1", color="#CCEBD6")
You can find additional examples and documentation on the dygraphs for R website.
One of the reasons we are excited about dygraphs is that it takes a mature and feature rich visualization library formerly only accessible to web developers and makes it available to all R users.