2016-03-22 49 views
0

我創建了以下圖表,以便我可以輕鬆比較不同時間段的多個時間序列。接下來我想添加一個選擇器,以便我可以選擇多個時間序列同時在劇情上查看,並取消選中我不想在劇情中查看的時間序列。操縱圖表選擇多個時間序列

代碼:

y<-series1 
r<-series2 
s<-series3 

require(graphics) 
manipulate( 
ts.plot(ts(y[x:(x+100)]),ts(r[x:(x+100)]),ts(s[x:(x+100)]),ts(t[x: (x+100)]),ts(h[x:(x+100)]), gpars=list(col = c("red","green","gray"))) 
, 
x=slider(1,length(y))) 

數據:

dput(series1[1:10]) 
c(9.5, 9, 14.5, 22.5, 13, 16, 22, 31.5, 51, 43) 


dput(series2[1:10]) 
c(20.3368220204774, 18.0733372276398, 16.61695493123, 15.6798824136643, 
15.0769466973063, 14.6890028922692, 14.4393902191708, 14.2787832298018, 
14.175444706505, 14.1089541357078) 

dput(series3[1:10]) 
c(17.8189147557743, 22.3815592342001, 16.108169527143, 21.0654757276344, 
16.3878646132368, 18.9345933680916, 16.634277276197, 15.4322081636797, 
20.2884280389731, 12.2089595405668) 
+0

我似乎無法下載軟件包,圖形。 – InfiniteFlashChess

+0

而且每個dput都分配了什麼?我非常困惑。請重寫東西! 另外,請告訴我們下載「minipulate」軟件包。 – InfiniteFlashChess

回答

0

你可以做這樣的

y<-c(9.5, 9, 14.5, 22.5, 13, 16, 22, 31.5, 51, 43) 
r<-c(20, 18, 17, 16, 15, 15, 14, 14, 14, 14) 
require(graphics) 
require(manipulate) 
manipulate({ 
    lines <- list(if (chk.y) ts(y), if(chk.r) ts(r)) 
    cols <- c(if (chk.y) "red", if (chk.r) "green") 
    do.call(ts.plot, c(lines, list(gpars=list(col=cols, xlab="t", ylab="y")))) 
}, 
    chk.y=checkbox(TRUE, "y"), 
    chk.r=checkbox(TRUE, "r") 
) 

enter image description here

+0

謝謝你,對你的代碼進行一些微小的修改就可以實現。回答'y <-tsValidation ř<-Acast $意味着 要求(圖形) 要求(操縱) 操縱({ 線< - 列表(如果(chk.y)TS(Y [X:(X + 100) (chk.r)ts(r [x:(x + 100)])) cols <-c(if(chk.y)「red」,if(chk.r)「green」) do.call(ts.plot,c(lines,list)(gpars = list(col = cols,xlab =「t」,ylab =「y」)))) }, chk.y = checkbox(TRUE,「 y「), chk.r =複選框(TRUE,」r「), x = slider(1,length(y)) ) – ndderwerdo