I have the following graph:
library(dygraphs)
set.seed(1)
date <- seq(as.Date("2010-01-01"), as.Date("2010-12-01"), by = "month")
var1 <- rnorm(length(date), mean = 100, sd = 10)
var2 <- rnorm(length(date), mean = 50, sd = 5)
df <- data.frame(date, var1, var2)
library(xts)
df_xts <- xts(df[,-1], order.by = df$date)
dygraph(df_xts, main = "Stacked Graph") %>%
dySeries("var1", label = "Var1") %>%
dySeries("var2", label = "Var2") %>%
dyOptions(stackedGraph = TRUE) %>%
dyRangeSelector(height = 20)
When I remove the grid lines, the colors seem to change:
dygraph(df_xts, main = "Stacked Graph") %>%
dySeries("var1", label = "Var1") %>%
dySeries("var2", label = "Var2") %>%
dyOptions(stackedGraph = TRUE) %>%
dyRangeSelector(height = 20) %>%
dyOptions(fillGraph = TRUE, drawGrid = FALSE)
Why is this happening and what can I do to fix this (i.e. make the colors in the second graph appear more similar to the first graph)?
Note: Here is the answer that worked for me based on @user20650's comment:
dygraph(df_xts, main = "Stacked Graph") %>%
dySeries("var1", label = "Var1") %>%
dySeries("var2", label = "Var2") %>%
dyOptions(stackedGraph = TRUE, drawGrid = FALSE)


Your use of multiple
dyOptionscalls is likely causing some options to be over-written. Soln: just use onedyOptionscall.Example:
Toggle the
drawGrid = FALSEoption to get the same plot with/without grid lines.