首页 > 解决方案 > R:function_list [[k]](值)中的错误:找不到函数“dyCandlestick”

问题描述

我正在尝试使用 R 的 dygraphs 包绘制历史外汇数据 - 使用 dyCandlestick 函数。出于某种原因,即使加载了 dygraphs 包,R 也没有找到 dyCandlestick 函数。

我已经成功运行了这段代码,但是我在下面显示的内容中添加了一些新行,现在它无法正常工作。我知道 tidyverse 与 xts 和 lubridate 的某些功能发生冲突,但无论如何我不明白该怎么做。

# historical Forex data obtained from:
#https://www.dukascopy.com/swiss/english/marketwatch/historical/

library(xts) # To make the convertion data-frame / xts format
library(lubridate)
library(dygraphs)
library(tidyverse)

raw_data <- read.csv("EURUSD_Candlestick_1_Hour_BID_01.01.2018-07.09.2019.csv") #data frame

i <- 1
time <- vector(length = nrow(raw_data))

for (when in raw_data$Local.time){
  dtz <- strsplit(when, " ")  #split date, time and GMT
  when <- paste(dtz[[1]][1], dtz[[1]][2]) #use only date and time
  datetime <- as.POSIXct(when, format = "%d.%m.%Y %H:%M:%OS")
  time[i] <- strftime(datetime, "%d-%m-%Y %H:%M:%OS")

  i<-i+1
}

#replace data with the new format
raw_data$Local.time <- NULL
raw_data$Local.time <- dmy_hms(time)
raw_data <- raw_data[c(1:77), ]

x = data.frame(raw_data$Open, raw_data$High, raw_data$Low, raw_data$Close)
#Candlestick charts use the first four data series to plot, the rest of the data series (if any) are rendered with line plotter
final_data <- xts(x = x, order.by = raw_data$Local.time)

dygraph(final_data) %>% dyCandlestick() #%>% dyOptions(sigFigs=5)

一旦我运行最后一行,我就会收到此错误消息: function_list [k] 中的错误:找不到函数“dyCandlestick”

任何帮助,将不胜感激!此外,非常感谢对本可以做得更好的代码的其他部分的评论 - 我对 R 有点陌生 :)

标签: rtrading

解决方案


推荐阅读