4

I am plotting a DYGraphs plot from an XTS object in R. The XTS object does not contain weekends in the data, however DYGraph seemingly by default puts them in. Is there a setting/option to stop this behavior? Setting the useDataTimezone to TRUE does not solve the issue.

Repeatable example:

library(xts)
library(dygraphs)

data <- data.frame(c("19/05/2016", "20/05/2016", "23/05/2016","24/05/2016"),c(1,2,2,4))
colnames(data) <- c("Timestamp", "Value")
data <- xts(data[,-1],order.by=as.POSIXct(data$Timestamp,  format = "%d/%m/%Y"), tz="UTC")

dygraph(data)

This has entries on the X axis for the 21st and 22nd May which creates a gap and a joining line on the chart which I do not want to display.I only want to display the dates listed in the XTS objects.

Ed Wilson
  • 267
  • 3
  • 12
  • You can remove the line across the missing dates by adding an `NA` value for a date between May 20 and May 23 (e.g. `data <- data.frame(Timestamp=c("19/05/2016", "20/05/2016","22/05/2016", "23/05/2016","24/05/2016"), Value=c(1,2,NA,2,4))`. I'm not sure if there's a way to force dygraphs to totally exclude the weekend as if that time gap didn't exist. I didn't see anything obvious while looking over [the documentation](http://dygraphs.com/). – eipi10 May 24 '16 at 03:28
  • @shreyasgm Yeah it is the same problem as my other post, however understanding the problem a little more has allowed me to re-phrase it. – Ed Wilson May 24 '16 at 04:03
  • @eipi10 yeah I have just done this but adding NAs to the data for the sake of the charting doesnt seem like a great solution to me. Surely there must be a way to have the chart display the x-axis from the data? If not, this essentially means anyone trying to use DY to chart financial or any other data that is only generated on weekdays is going to have this issue!? – Ed Wilson May 24 '16 at 04:08
  • I haven't really used dygraphs, so I don't know if there's a way to completely remove the weekends. However, in case it might be helpful, [here are some methods to remove weekends and holidays in static ggplot graphs](http://stackoverflow.com/questions/32893176/ggplot2-remove-blank-space-for-weekends-and-holidays-from-x-axis-dates/32901109#32901109). – eipi10 May 24 '16 at 04:32
  • 1
    you should delete one of your post. There are duplicates – MLavoie May 24 '16 at 10:00
  • See: https://github.com/rstudio/dygraphs/issues/70 – Jav May 24 '16 at 10:09

0 Answers0