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.