Reputation: 8074
I plotted a dygraph using a dygraph
function from a dygraphs package. My data were from dates 2014-12-10 till 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 on a plot legend says they start 1 day ealier, check this figure: On axis there is a date 12, but on legend there is a date 11...
Any idea where is a bug?
To reproduce this bug 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've also posted this as an issue on rstudio's github https://github.com/rstudio/dygraphs/issues/22
Upvotes: 3
Views: 876
Reputation: 139
Under the dyOptions
add labelsUTC = FALSE
. Alternatively, useDataTimezone = TRUE
Example dyOptions(labelsUTC = FALSE)
Upvotes: 0
Reputation: 930
It's strange to be honest, it looks like the problem is not only with timezones but with scale also.
In theory dygraph uses the time zone of the client workstation, check this. But internally it keeps time in GMT (not sure about this, but it looks so), 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 time zone so I get 1 hour difference.
Now, because dyGraph uses my time zone, everything should be OK, but it isn't. However, if you change scale of dygraph by hand:
d$x$scale <- "hourly"
it starts to work as intended. So maybe some issues with extracting days?
According to docs you could set option to use timezone from data
indexTZ(seriesReactive) <- "CET"
dygraph(seriesReactive, main = "Dzienna proporcja kliknięć do odsłon dla danych struktur", ylab = "Proporcja") %>%
dyOptions(useDataTimezone = TRUE) %>%
dyRangeSelector()
but it doesn't work for me (nothing shows up). I don't know why but I don't have time to drill into this.
You could always make small workaround and set timezone to GMT in xts
object.
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()
Upvotes: 1