在Dygraphs中有一个选项来填补下面的内容:
library(dygraphs) lungDeaths <- cbind(ldeaths, mdeaths, fdeaths) dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>% dySeries("fdeaths", stepPlot = TRUE, color = "red", fillGraph = TRUE)我的问题是:如何填补上方的区域?
There is an option in Dygraphs to fill the aera under the lines:
library(dygraphs) lungDeaths <- cbind(ldeaths, mdeaths, fdeaths) dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>% dySeries("fdeaths", stepPlot = TRUE, color = "red", fillGraph = TRUE)My question is: how to fill the area above the lines?
最满意答案
这是目前我能得到的最接近的。 你必须创建阴影图的幻觉 。 您必须创建一个顶部虚拟数据集来完成此操作,以绘制您询问的内容。 在此之后,您可以设置轴限制以获得您所问的内容。
注意:由于我们将它们堆叠到彼此的顶部,所以底部部分相当复杂。 这不是理想的(下面有什么)。
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))
如果你想要一个较大的差距,然后尝试添加一些其他的虚拟值,像这样。
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))
This is the closest I can get, at this time. You've got to create the illusion of a shaded graph. You have to create a top dummy dataset to accomplish this to plot what you're asking about. After this, you can set the axis limits to get what you asked about.
Note: The bottom portion is rather tricky to include given we are stacking them onto top of each other. It's not ideal (what's posted below).
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))If you want a large gap below, then try adding some other dummy values, like this.
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))更多推荐
发布评论