2012-06-19 18 views
5

我想在quantmod :: chart_Series()之上繪製一些支持/阻力線。問題在於,有趣的支持/阻力線在系列數據範圍之外(低於或高於)當前時間(我還想將圖表向右延伸超過上次數據時間戳)。在quantmod :: chart_Series()中使用xlim/ylim或xrange/yrange覆蓋y尺度和x尺度 - 不可能嗎?

查看quantmod :: chart_Series()的源代碼我看不出指定ylim/xlim的方法,或者在「過去的日子」中使用quantmod :: chartSeries使用yrange覆蓋y-scale的可能性。這裏評論https://r-forge.r-project.org/scm/viewvc.php?view=rev&root=quantmod&revision=520也確認我的預感...

我的診斷是否正確,或者有可能在quantmod :: chart_Series中啓用y-scale覆蓋的方法?任何想法如何做我想得到高度讚賞。

謝謝。

最佳, 薩莫

回答

5

chart_Series()筆記幫助頁面 - 三次! - 它是實驗性的,所以推測最終的拋光版本可以設置這些限制。

在此之前,這裏是一個黑客(?),可以讓你設定的限制可以教你一些關於如何chart_Series()作品(通過創建"replot"類的環境/關閉,存儲所有信息的即需要創建一個圖表)。

## Create an example plot 
getSymbols("YHOO") 
myChob <- chart_Series(YHOO) 

## Plot it, with its default xlim and ylim settings 
myChob 


## Get current xlim and ylim settings for `myChob` (chob = chart object) 
myxlim <- myChob$get_xlim() 
myylim <- myChob$get_ylim() 

## Alter those limits 
myxlim <- c(1, 2000) 
myylim[[2]] <- structure(c(0, 50), fixed=TRUE) 

## Use the setter functions in the myChob environment to set the new limits. 
## (Try `myChob$set_ylim` and `ls(myChob$Env)` to see how/where these are set.) 
myChob$set_ylim(myylim) 
myChob$set_xlim(myxlim) 

## Plot the revised graph 
myChob 
+0

完美。 thnx洞察如何做到這一點。 – Samo

+0

謝謝! chart_Series()代碼很難閱讀,所以很高興看到這樣的例子。 「fixed = T」是什麼意思?對於myylim [[2]],'fixed = F'失敗,它必須是真的;但是爲了改變'myxlim',它似乎可以是真或假。什麼是myylim [1]?我看到玩它似乎移動標題,但再次固定可以是真或假! –