我正在尝试在我的高位图表上制作一个功能区(大致在is there an equivalent to geom_ribbon in highcharter?之后)。
但是,以下示例在R
中生成高图表图形会产生错误:
library(quantmod)
library(dplyr)
library(highcharter)
getSymbols("VOD")
bb_data = BBands(Cl(VOD), n=20)
highchart(type = "stock") %>%
hc_add_series(bb_data, type = "arearange", hcaes(low = dn, high=up))
错误是:Error: 'hcaes(low = dn, high = up)' argument is not named in hc_add_series
我认为这是因为它是一个时间序列对象(xts)。
如果我将其强制转换为data.frame,但随后丢失日期,则可以使用。
highchart(type = "stock") %>%
hc_add_series(as.data.frame(bb_data), type = "arearange", hcaes(low = dn, high=up))
我无法将其与移动平均线或价格数据结合起来,因为随后的绘图缺少了功能区:
highchart(type = "stock") %>%
hc_add_series(Cl(VOD), name = "VOD") %>%
hc_add_series(bb_data$mavg, name = "20d MA") %>%
hc_add_series(as.data.frame(bb_data), type = "arearange", hcaes(low = dn, high=up))
好,所以我必须首先从时间序列对象中提取日期,并将其与时间序列对象绑定以形成数据框或数据表,然后使用该图像进行绘图。
bb_data2 = cbind(date = as.Date(index(bb_data)), data.table(bb_data))
highchart(type = "stock") %>%
hc_add_series(bb_data2, type = "arearange", hcaes(x=date, low = dn, high=up)) %>%
hc_add_series(Cl(VOD), name = "VOD") %>%
hc_add_series(bb_data$mavg, name = "20d MA")