使用带有xts-object的dygraph在绘图中删除Label

时间:2015-10-16 18:49:42

标签: r xts dygraphs

我有一个看似很小的挑战,但我无法得到答案。这是我最小的工作示例。

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")

结果:

  

dySeries中的错误(。,&#34; V1&#34;,label =&#34; Label1&#34;):一个或多个   未找到指定的系列。有效的系列名称为:..1,..2,.3

但是,如果我只绘制一个系列(例如series1),它就可以工作。

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

1 个答案:

答案 0 :(得分:1)

colnames对象设置grp_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")