dygraphs icon indicating copy to clipboard operation
dygraphs copied to clipboard

Graphing negative and positive numbers?

Open smach opened this issue 10 years ago • 5 comments

I'm trying to graph data with negative and positive numbers. In this example of daily high and low temperatures in Fargo, ND - csv file here - my graph y axis is just showing 1 to -13 and the data is not showing properly.

fargo <- read.csv("fargoTemps2014.csv", colClasses = c("Date", "integer", "integer"))
fargo_for_graph <- xts::xts(fargo, order.by = fargo$Date)
dygraph(fargo_for_graph)

fargograph

smach avatar Jan 30 '15 22:01 smach

I have the same issue when I try to have the data has both positive and negative values.

In my case, all the series which only contain positive values can be displayed well. But the data which are all negative cannot be seen any more.

wushuzh avatar Aug 26 '15 01:08 wushuzh

Same issues on my end. @jjallaire should we expect to see this issue addressed?

screen shot 2016-08-31 at 10 46 54 am

yuanagain avatar Aug 31 '16 17:08 yuanagain

I'm having the same issues. It looks like when values are just negative it flips the y axis and shows from 0 up to my minimum value (-50 for example). But when there are both positive and negative values, it does not show the negative ones as demonstrated above. Would love to see a fix for this.

GrayAlex49 avatar Nov 23 '16 18:11 GrayAlex49

Same here. This seems like it should be a relatively easy fix.

brianlevey avatar Jan 12 '17 16:01 brianlevey

I am able to hack my way out of this problem by adding a valueRange to the y axis:

library(dygraphs)
library(xts)

date <- Sys.Date()
data <- data.frame(Date = c(date + 1, date + 2, date + 3, date + 4),
                   Value = c(1, 4.2, 5, -0.3))
xtsdata <- xts::xts(data, order.by = data$Date)

padrange <- c(min(data$Value) - 1, max(data$Value) + 1)

dygraph(xtsdata) %>%
  dyRangeSelector() %>%
  dyAxis("y", valueRange = padrange)

However, this does not fix the problem in the rangeSelector. Any data with negative values will simply yield a blank rangeSelector. Any suggestions on how to set the y-axis on the rangeSelector?

sebdalgarno avatar Nov 01 '17 20:11 sebdalgarno