Date error in dygraph in package dygraphs (using JavaScript) in R

I have plotted a chart using a function dygraph

from the dygraphs package . My details were from 2014-12-10 to 2014-12-17

> str(seriesXts)
An ‘xts’ object on 2014-12-10/2014-12-17 containing:
  Data: num [1:8, 1:30] 0.928 0.977 0.935 0.989 0.854 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:30] "CiekawostkiFinanse" "CiekawostkiKobieta" "CiekawostkiMototech" "CiekawostkiSport" ...
  Indexed by objects of class: [POSIXct,POSIXt] TZ: 
  xts Attributes:  
List of 1
 $ descr: chr "my new xts object"

      

but the plot legend says they start 1 day elf, check this metric: There is date 12 on the axis, but according to legend there is date 11 ...

bug

Any idea where the error is?

To reproduce this error try this code

library(archivist)
library(dplyr)
library(devtools)
devtools::install_github("rstudio/dygraphs")
library(dygraphs)
seriesReactive <- loadFromGithubRepo( "db914a43536d4d3f00cf3df8bf236b4a", user= "MarcinKosinski", repo="Museum", value = TRUE)
dygraph(seriesReactive, main = "Dzienna proporcja kliknięć do odsłon dla danych struktur", ylab = "Proporcja") %>% 
    dyRangeSelector()

      

I also posted this as an issue for rstudio github https://github.com/rstudio/dygraphs/issues/22

+3


source to share


1 answer


Strange, to be honest, it looks like the problem is not only with time zones, but also with scale.

In theory dygraph uses the timezone of the client workstation, check this . But internally it keeps the time in GMT (not sure about it, but it looks like this), look: d <- dygraph(seriesReactive, main = "Dzienna proporcja kliknięć do odsłon dla danych struktur", ylab = "Proporcja") %>% dyRangeSelector() d$x$data[[1]] [1] "2014-12-09T23:00:00Z" "2014-12-10T23:00:00Z" "2014-12-11T23:00:00Z" "2014-12-12T23:00:00Z" [5] "2014-12-13T23:00:00Z" "2014-12-14T23:00:00Z" "2014-12-15T23:00:00Z" "2014-12-16T23:00:00Z"

I am in CET timezone, so I get 1 hour difference.

Now, since dyGraph is using my timezone, everything should be OK, but it isn't. However, if you change the scale of the digraph manually: d$x$scale <- "hourly"

it starts working as intended. Maybe some problem with retrieving days?



According to the docs, you can set the option to use the timezone from the data indexTZ(seriesReactive) <- "CET" dygraph(seriesReactive, main = "Dzienna proporcja kliknięć do odsłon dla danych struktur", ylab = "Proporcja") %>% dyOptions(useDataTimezone = TRUE) %>% dyRangeSelector()

but that doesn't work for me (nothing appears). I don't know why, but I don't have time for this.

You can always do a little workaround and set the timezone for GMT to xts

. index(seriesReactive) <- as.POSIXct(format(index(seriesReactive), format="%Y-%m-%d"), tz = "GMT") dygraph(seriesReactive, main = "Dzienna proporcja kliknięć do odsłon dla danych struktur", ylab = "Proporcja") %>% dyRangeSelector()

+1


source







All Articles