user189035
user189035

Reputation: 5789

Dygraphs: fill area above series

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?

Upvotes: 0

Views: 736

Answers (1)

InfiniteFlash
InfiniteFlash

Reputation: 1058

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

Upvotes: 2

Related Questions