dyAxis valueRange problem in dygraphs library

Hi Everyone,

I came across the following problem when using dygraphs library in R/Shiny report.
Documentation says that I can set Y axis boundaries using valueRange property of dyAxis:

valueRange: Explicitly set the vertical range of the graph to c(low, high) . This may be set on a per-axis basis to define each y-axis separately. If either limit is unspecified, it will be calculated automatically (e.g. c(NULL, 30) to automatically calculate just the lower bound).

I would like to set the lower limit to 0 and use NULL so that the higher value is calculated automatically (I don't know the maximum value my graph can achieve).

Here is a snippet that doesn't work as expected:

day <- c(as.Date("2020-01-01"),as.Date("2020-01-02"),as.Date("2020-01-03"),as.Date("2020-01-04"),as.Date("2020-01-05"),as.Date("2020-01-06"))
value <- c(200, 300, 400, 350, 250, 375)
df <- data.frame(day,value)
dfXts <- xts(df[,-1], order.by = df[, 1])
graph <-  dygraph(dfXts) %>% dyAxis('y', valueRange = c(0, NULL)) %>% dySeries(name = "V1", label="VALUE", axis = 'y')
graph

I expect that setting valueRange = c(0, NULL) will make Y axis start at 0 and end in this case with ~450.
Unfortunatelly the Y axis starts with 180.


I need to replace NULL with specific value, then it works fine:
valueRange = c(0, 450)

I rarely know the maximum values, so setting it explicitly is problematic.

Any help do solve this issue appreciated.

BR
Peter

Hi @Peter.P. I see the help of dyAxis and try different values. It seems the description of the argument valueRange are mistyping. You should use NA instead of NULL. You may summit an issue to the package to inform the author.

graph <-  dygraph(dfXts) %>% dyAxis('y', valueRange = c(0, NA)) %>% dySeries(name = "V1", label="VALUE", axis = 'y')
1 Like

Thank you! I didn't come up with an idea to check NA instead of NULL.
I reported it as an issue at https://github.com/rstudio/dygraphs/issues

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.