I am working with the R programming language.
I have the following data:
library(dygraphs)
var1 = c(5,5,8,13,14,12,11,10,9,60, 50,40)
var2 = c(13,13,22,30,35,31,25,24,20,20,20,21)
var1 <- ts(var1, start = 2010, frequency = 12)
var2 <- ts(var2, start = 2010, frequency = 12)
df2 = cbind(var1, var2 = var2 - var1)
I then made the following stacked graph (based on the answer provided here (https://stackoverflow.com/a/77041702/13203841):
dygraph(df2, main = "Graph") %>%
dySeries("var1", label = "Var1") %>%
dySeries("var2", label = "Var2") %>%
dyOptions(stackedGraph = TRUE) %>%
dyRangeSelector(height = 20)

My Question: I can see that the value of the green line on the y-axis DOES NOT match the value in the label (top right corner). However, the value on the y-axis itself is correct.
What can I do to fix this?
Thanks!
When you use dyOptions(stackedGraph = TRUE), you enable the stacking of the series, and the label is showing the total (sum) of the two groups. In other words the label in the top right corner represents the sum of the stacked series rather than the individual values of var2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With