Dygraphs:填充系列上方的区域

时间:2017-12-28 18:42:33

标签: r dygraphs

Dygraphs中有一个选项可以填充以下内容:

library(dygraphs)
lungDeaths <- cbind(ldeaths, mdeaths, fdeaths)
dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>%
  dySeries("fdeaths", stepPlot = TRUE, color = "red", fillGraph = TRUE)   

我的问题是:如何填充以上行的区域?

1 个答案:

答案 0 :(得分:2)

这是我目前最接近的。您必须创建着色图的幻觉。您必须创建一个顶部虚拟数据集才能完成此操作以绘制您所询问的内容。在此之后,您可以设置轴限制以获得您所询问的内容。

注意:如果我们堆叠它们彼此重叠,那么底部部分相当棘手。这不太理想(下面发布的内容)。

library(dygraphs)

top <- structure(rep(10000, 72), .Tsp = c(1974, 1979.91666666667, 12), class = "ts")


lungDeaths <- cbind(top, ldeaths, mdeaths, fdeaths)


dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>%
  dyLegend(show = "never", hideOnMouseOut = FALSE)%>%
  dyOptions(stackedGraph = TRUE)%>%
  dyRangeSelector()%>%
  dyAxis("y", valueRange = c(0, 8000))

enter image description here

如果你想要一个较大的间隙,那么尝试添加一些其他虚拟值,如下所示。

lungDeaths <- cbind(top, ldeaths, mdeaths, fdeaths, top)

dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>%
  dyLegend(show = "never", hideOnMouseOut = FALSE)%>%
  dyOptions(stackedGraph = TRUE)%>%
  dyRangeSelector()%>%
  dyAxis("y", valueRange = c(8000, 20000))

enter image description here