2015-10-16 74 views
1

我有一個看似小的挑戰,但我無法得到答案。這是我最低工作的例子。使用dyxt與xts對象滴標籤在劇情

fr_nuke <- structure(list(Date = structure(c(1420070400, 1420074000, 1420077600, 
    1420081200, 1420084800, 1420088400), class = c("POSIXct", "POSIXt"), tzone = ""), 
    `61` = c(57945, 57652, 57583, 57551, 57465, 57683), 
    `3244` = c(72666.64, 73508.78, 69749.17, 67080.13, 66357.65, 66524.13), 
    `778` = c(2.1133, 2.1133, 2.1133, 2.1133, 2.1133, 2.1133), 
    fcasted_nuke_temp = c(54064.6099092888, 54064.6099092888, 54064.6099092888, 
    54064.6099092888, 54064.6099092888, 54064.6099092888), 
    fcasted_nuke_cons = c(55921.043096775, 56319.5688170977, 54540.4094334057, 
    53277.340242333, 52935.4411965463, 53014.2244890147)), 
    .Names = c("Date", "61", "3244", "778", "fcasted_nuke_temp", "fcasted_nuke_cons"), 
    row.names = c(NA, 6L), class = "data.frame") 

series1 <- as.xts(fr_nuke$'61', fr_nuke$Date) 
series2 <- as.xts(fr_nuke$fcasted_nuke_temp, fr_nuke$Date) 
series3 <- as.xts(fr_nuke$fcasted_nuke_cons, fr_nuke$Date) 
grp_input <- cbind(series1,series2,series3) 

dygraph(grp_input) 

所得的情節也不會顯示個別系列的標籤。與

dygraph(grp_input) %>% dySeries("V1", label = "Label1") 

結果指定系列:(。, 「V1」,標籤= 「Label1的」)

錯誤dySeries:一個或多個指定的 系列都沒有發現。有效的系列名稱是:..1,.2,.3

但是,如果我只繪製一個系列(例如series1),它將起作用。

dygraph(series1) %>% dySeries("V1", label = "Label1") 

回答

1

要麼設置colnamesgrp_input對象,或使用merge從對象名稱構造的列名。

# setting colnames 
require(dygraphs) 
require(xts) 
grp_input <- cbind(series1, series2, series3) 
colnames(grp_input) <- c("V1", "V2", "V3") 
dygraph(grp_input) %>% dySeries("V1", label = "Label1") 

# using merge 
require(dygraphs) 
require(xts) 
grp_input <- merge(series1, series2, series3) 
dygraph(grp_input) %>% dySeries("series1", label = "Label1")