R chartSeries 添加带点的额外图表

R chartSeries add extra chart with points

我对 chartSeriesR 中的 addTA / points.default 函数有疑问。我正在尝试在 chartSeries-plot 下面添加一个额外的图表,其中包含不同颜色的点(着色取自函数并使用 points.default),但不幸的是我无法添加这些点addTA。我可以在现有图表中添加一条线(两者都不是我想要的)。 points.default 函数只是将这些点添加到 chartSeries 中,这不是我想要的。我正在寻找一条简单的直线点,我可以用我的 color_fct 进行不同的着色,并将其添加到我的 chartSeries 下方。感谢您的帮助,并提前致谢!

示例代码:

getSymbols("YHOO")
data <- YHOO
chartSeries(data, type = c("auto", "candlesticks", "matchsticks","bars","line"))
hero<-rep(1,length(data$Close))
c(data, xts(hero))
#addTA provides me with a straight line and the coloring fct is not working
plot(addTA(data$hero,pch = 15,cex = 1.5, on = 2, col = color_fct))
#points.default provides me with perfect coloring, but the points are plotted in the middle of the chart
help<- rep(1, length(data$Close))
points.default(x=(1:length(data$High)),y=help+1, col= color_fct,pch = 15,cex = 1.5)

如果您愿意使用较新的 chart_Series 而不是 chartSeries

x_ti <- xts(rnorm(NROW(data)), order.by = index(data))
x_ti2 <- xts(rep(1, NROW(data)), order.by = index(data))
x_ti2[1, ] <- 0.5 # work around to get an xts object with all the same values (of 1) to plot if points are not visible on the subplot

chart_Series(data["2017"])
add_TA(x_ti, col = "purple", pch = 15, type = 'p', cex = .7)
# plot straight line in subplot:
add_TA(x_ti2, col = "orange", pch = 9, type = 'p', cex = .7)