2017-02-10 30 views
2

chartSeriesaddTA/points.default에 관한 질문이 R입니다. chartSeries -plot 아래에 다른 색상의 점으로 플롯을 추가하려고합니다 (색상 표시는 기능에서 가져오고 points.default과 작동 함). 그러나 불행히도이 점을 addTA과 함께 추가 할 수 없습니다. 기존 차트에 선을 추가 할 수 있습니다 (둘 다 찾고있는 것이 아닙니다). points.default 함수는 해당 점을 chartSeries에 추가하기 만하면됩니다. 이는 내가 찾고있는 것이 아닙니다. 나는 내 color_fct과 다르게 착색 할 수있는 포인트의 간단한 직선을 찾고 있는데, 이는 내 chartSeries 아래에 추가됩니다. 어떤 도움을 주셔서 감사 드리며 미리 감사드립니다!R 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) 

답변

1

당신은 chartSeries 대신 chart_Series 새로운를 사용하여 열려있는 경우 :

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) 

enter image description here

+0

불행하게도, 나는 버그를 발견. 반짝이는 슬라이더를 사용하고 있습니다. 슬라이더는'chart_Series'에서 완벽하게 작동하지만 직선에는 문제가 있습니다. 확대 할 때마다 왼쪽에있는 값을 수정합니다. 오른쪽으로 확대하면 왼쪽의 값이 남아있는 반면,'chart_Series'는 오른쪽을 확대합니다. 'zoom_chart'가 당신의 대답을 확대 할 수있는 옵션이 있습니까? – Simon

+0

나는 당신의 코드를 이해하는 한, chart_Series와 관계없이 별도의 Chart를 추가한다. 이것은 올바른 가정입니까? 두 차트를 연결하는 방법이 있습니까? – Simon

+0

Shiny :'chart_Series (data [ "2017"], TA = 'add_TA (x_ti, col = "보라색", pch = 15, type = "p", cex = .7)를 사용하면 모든 항목을 이와 함께 차트로 표시 할 수 있습니다.), add_TA (x_ti2, col = "orange", pch = 9, type = "p", cex = .7) ')' – FXQuantTrader