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:

colours

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

Similar Reads

Creating simple dygraphs

Let’s take stock data for a better understanding of time series....

Series color graph

...

Vertical and Horizontal shading

Dygraph can assign different color palettes to each visualization line. For example, our four-parameter in TSLA data (open, high, low, close) can be represented as different colors. Dygraph provides dyOptions() in which colors parameter can be useful to identify each stock line smoothly....

Candlestick graph

...

Upper/lower bar

Vertical shading:...

Range Selector

...

Contact Us