Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: Labels on Graph Don't Match Data

Tags:

r

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)

enter image description here

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!

like image 717
stats_noob Avatar asked Oct 23 '25 16:10

stats_noob


1 Answers

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.

like image 168
Ada Avatar answered Oct 26 '25 07:10

Ada



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!