Creating simple dygraphs
Let’s take stock data for a better understanding of time series.
Download (Tesla) Stock data from the quantmod library by using getSymbols(). We will plot 5 different dynamic plots.
- Series colour
- Vertical and Horizontal Shading
- Candlestick
- Upper/lower bar
- Range Selector
First of all, install dygraphs and quantmod package in rstudio.
install.packages(“dygraphs”)
install.packages(“quantmod”)
You can download data directly from this link: TSLA Stock Data
Here, OHLC represents the open, high, low, and closing price of each period in stock data. So, we are fetching this parameter and storing it in the price variable.
R
# import library library (dygraphs) library (quantmod) # download data getSymbols ( "TSLA" ) # view top 5 row data head (TSLA,n=5) # Get OHLC data price<- OHLC (TSLA) head (price, n=5) |
Output:
How to use interactive time series graph using dygraphs in R
Dygraphs refer to as Dynamic graphics which leads to an easy way to create interaction between user and graph. The dygraphs are mainly used for time-series analysis. The dygraphs package is an R interface to the dygraphs JavaScript charting library in R Programming Language.