Dygraphs is a neat package that can be used to plot time series interactively. This makes it much easier to explore a time series, and the final result actually looks pretty good as well.
First, let’s get a time series of the AEX stock market index using quantmod::getSymbols:
library(quantmod)
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## Loading required package: TTR
## Version 0.4-0 included new data defaults. See ?getSymbols.
getSymbols('^AEX')
## As of 0.4-0, 'getSymbols' uses env=parent.frame() and
## auto.assign=TRUE by default.
##
## This behavior will be phased out in 0.5-0 when the call will
## default to use auto.assign=FALSE. getOption("getSymbols.env") and
## getOptions("getSymbols.auto.assign") are now checked for alternate defaults
##
## This message is shown once per session and may be disabled by setting
## options("getSymbols.warning4.0"=FALSE). See ?getSymbols for more details.
## [1] "AEX"
plot(AEX$AEX.Open)
That is the standard time series plot, which is non-interactive. By using the dygraph plot, we can click around in the plot to get specific values and to zoom in on specific time series.
library(dygraphs)
dygraph(AEX, main="AEX") %>% dyRangeSelector()
You can also easily put a second column on the secondary axis, e.g. the trade volume:
dygraph(AEX, main="AEX") %>% dyRangeSelector() %>%
dySeries("AEX.Volume", axis = 'y2')
You can also set the selected line to highlight, which is useful if you have a lot of series in a single plot:
dygraph(AEX, main="AEX") %>% dyRangeSelector() %>%
dySeries("AEX.Volume", axis = 'y2') %>%
dyHighlight(highlightCircleSize = 5, highlightSeriesBackgroundAlpha = 0.2)
Finally, you can easily smooth the series by taking a moving average:
dygraph(AEX, main = "AEX") %>%
dySeries("AEX.Volume", axis = 'y2') %>%
dyRoller(rollPeriod = 10)
And see more examples at http://dygraphs.com/gallery/