Dygraphs:填充上面的区域(Dygraphs: fill area above series)

编程入门 行业动态 更新时间:2024-10-25 15:21:52
Dygraphs:填充上面的区域(Dygraphs: fill area above series)

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

enter image description here

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

enter image description here

更多推荐

本文发布于:2023-04-27 15:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327135.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:区域   Dygraphs   fill   series   area

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!