2016-11-20 9 views
0

Rダイグラフでは、日ごとに、複数の日に渡って領域を網羅することなく、どのように領域を網羅するのですか?たとえば、次の例では毎日07:00〜08:15に日陰をつけたいと考えています(私の完全な例はもっと多くの日数を持っています)。rdygraphs複数の日に亘って時間帯に網掛けされた領域

#generate data 
library(xts) 
library(dygraphs) 

#generate sample data 
#http://stackoverflow.com/questions/9778632/r-xts-generating-1-minute-time-series-from-second-events 
x <- xts(cumsum(rnorm(400000, 0, 0.2)), Sys.time() - 400000:1) 
x <- to.minutes(x) 

#display dygraph 
dygraph(x) %>% 
    dyCandlestick() %>% 
    dyRangeSelector(height=20) 

ありがとう!

+0

''エラーが発生しました[[ i]](値): できませんでしたd function "dyCandlestick" "私はその機能が廃止されたと思います。 –

+0

シェーディングの目的では、燭台、折れ線グラフ、棒グラフなどは重要ではありませんが、燭台は非常に多くサポートされていますが、https://rstudio.github.io/dygraphs/gallery-candlestick.html – Russell

+0

また、 sessionInfoは私が実行していることを示しています** dygraphs_1.1.1.3 ** – Russell

答えて

0

私は私の問題を解決することができました。コードは、参考のために以下の通りです:また

、アイデアを次のように感謝:function_listで

R xts: generating 1 minute time series from second events

R How to shade week-end period with dygraphs?

http://databasefaq.com/index.php/answer/20331/r-dygraphs-dyshading-r-dygraph


#load libraries 
library(xts) 
library(dygraphs) 

#generate sample data 
x <- xts(cumsum(rnorm(400000, 0, 0.2)), Sys.time() - 400000:1) 
x <- to.minutes(x) 

#display dygraph without shading 
dygraph(x) %>% 
    dyCandlestick() %>% 
    dyRangeSelector(height=20) 


##################### 
#function to creating shading in a list 
add_shades <- function(x, periods, ...) { 
    for(period in periods) { 
    x <- dyShading(x, from = period$from , to = period$to, ...) 
    } 
    x 
} 

##################### 
#creates the list that feeds into the "add_shades" function 
ok_periods<-0 
i=1 
j=1 
while (i<(length(index(x[(.indexhour(x)==9 & .indexmin(x)==30)])))){ 
    ok_periods[j] <- list(list(from = index(x[(.indexhour(x)==16 & .indexmin(x)==15)][i]), to = index(x[(.indexhour(x)==9 & .indexmin(x)==30)][i+1]))) 
    i=i+1 
    j=j+1 
} 

##################### 
#graph with shading 
dygraph(x) %>% 
    dyCandlestick() %>% 
    add_shades(ok_periods, color = "#FFFFCC") %>% 
    dyRangeSelector(height=20) 
+0

参考になったもう一つのリンク:http://stackoverflow.com/questions/11871572/subsetting-tricks-for-xts-in-r – Russell

関連する問題