가장 먼저 알아야 할 것은 zoomChart()
이 원하는 값을 반환하지만 zooom()
은 그렇지 않습니다.
zoomChart()
은 invisible(chob)
줄로 끝나는 reChart()
함수를 호출하기 때문에 발생합니다. (chob
은 나중에 참조 할 개체의 이름입니다.)
zooom()
이 작업을 수행하지 않습니다. zoomChart()
이 호출되지만 zoomChart()
이 평가되는 환경 밖에서 chob
을 전달하지 않습니다. 내가 만든
require(quantmod)
dump("zooom", file="zooom2.R")
세 가지 편집이 있었다 : 당신이 먼저라는 편집 기능 zooom2
을 생성 한 후 파일에 zooom
덤핑에 의해 zooom()
내가 이런 짓을의 수정 된 버전을 만들어,하지만, 그렇게 할 수 :
는 quantmod:::get.chob()
호출로 get.chob()
에 전화를 교체합니다. 이는 zooom
과 달리 zooom2
의 봉투 환경이 namespace:quantmod
이 아니기 때문에 필요합니다.
zoomChart()
의 출력을 chob
개체에 할당합니다.
invisible(chob)
으로 끝내서 호출 환경에 chob
을 반환하십시오.
zooom2 <-
function (n = 1, eps = 2)
{
for (i in 1:n) {
cat("select left and right extremes by clicking the chart\n")
points <- locator(2)
if (abs(diff(points$x)) < eps) {
zoomChart()
}
else {
usr <- par("usr")
xdata <- quantmod:::get.chob()[[2]]@xdata
xsubset <- quantmod:::get.chob()[[2]]@xsubset
sq <- floor(seq(usr[1], usr[2], 1))
st <- which(floor(points$x[1]) == sq)/length(sq) *
NROW(xdata[xsubset])
en <- which(floor(points$x[2]) == sq)/length(sq) *
NROW(xdata[xsubset])
sorted <- sort(c(st, en))
st <- sorted[1]
en <- sorted[2] * 1.05
chob <- zoomChart(paste(index(xdata[xsubset])[max(1, floor(st),
na.rm = TRUE)], index(xdata[xsubset])[min(ceiling(en),
NROW(xdata[xsubset]), na.rm = TRUE)], sep = "::"))
}
}
cat("done\n")
invisible(chob)
}
당신은 소스 또는 붙여 넣기 기능을 다시 R 세션으로, 다음 (예를 들어)과 같이 사용할 수 있습니다 :
data(sample_matrix)
chartSeries(sample_matrix)
d <- zooom2()
# Click to interactively zoom in
# extract the data visible in the selected region
d_sub <- [email protected][[email protected],]
head(d_sub)
# Open High Low Close
# 2007-03-28 48.33090 48.53595 48.33090 48.53595
# 2007-03-29 48.59236 48.69988 48.57432 48.69988
# 2007-03-30 48.74562 49.00218 48.74562 48.93546
# 2007-03-31 48.95616 49.09728 48.95616 48.97490
# 2007-04-01 48.94407 48.97816 48.80962 48.87032
# 2007-04-02 48.90488 49.08400 48.90488 49.06316
여기
수정 된 함수의 이것이 유용한 경우라면, 소스 코드
quantmod
에 추가하고, 자신의 패키지 버전을 다시 컴파일 할 수 있습니다.
희망이 도움이됩니다.
chartSeries는 timeseries에 표시가있는 xrange 속성을 포함하여 차트에 대한 다양한 세부 정보를 지정하는 속성이있는 객체를 반환한다는 것을 발견했습니다. 그러나, zooom을 호출하면 chartSeries에 의해 반환 된 원래 객체의 속성이 수정되지 않고 zooom이 아무 것도 반환하지 않습니다. –
수정 범프 죄송합니다. 지금은 철자 ['zooom'] (https://github.com/joshuaulrich/quantmod/search?utf8=%E2%9C%93&q=zooom&type=) 기능이 있음을 알고 있습니다.) –