Plot series in same dyGraph with dyCandlestick in R

269 views Asked by At

How to add series with dyCandlestick. The data has columns "timestamp", "open", "high", "low", "close", "volume", "mean_value", "ma_20", "ma_50". Following code gives me a right candlestick chart.

  library(tidyverse)
  dt <- read_csv("https://raw.githubusercontent.com/amandeepfj/RawData/master/top_rows.csv")

  dt.dy <- xts::xts(x = dt[, c("open", "high", "low", "close")], 
                    order.by = as.POSIXct(dt$timestamp))

  dygraph(dt.dy) %>%
    dyCandlestick() %>% 
    dyRangeSelector()

I want to show ma_20 & ma_50 in the same dygraph. I tried to pipe(%>%) dySeries, but it does not work.

1

There are 1 answers

2
Garima Gulati On

You can combine the moving average series in the graph data: dt.dy.

library(dygraphs)
dt <-read_csv("https://raw.githubusercontent.com/amandeepfj/RawData/master/top_rows.csv")
dt.dy <- xts::xts(x = dt[, c("open", "high", "low", "close", "ma_20", "ma_50")], order.by = as.POSIXct(dt$timestamp))
dygraph(dt.dy) %>% dyCandlestick() %>% dyRangeSelector()