I have the following data set called "my_data" (a data frame) - the dates are "factor types" and represent "year-month" (note: this data frame was created from an original data frame using the "dplyr group_by/summarise" commands - and then the "pivot_longer" command in "tidyverse" to make the data in "long format") :
head(my_data)
col_A.dates col_A.count col_B.count col_C.count col_D.count col_E.count
1 2010-01 189 130 57 58 53
2 2010-02 63 62 25 18 30
3 2010-03 46 24 12 12 11
4 2010-04 45 17 8 16 15
5 2010-05 42 26 13 12 16
I am trying to make a time series plot of this data using the "dygraph" library (https://rstudio.github.io/dygraphs/).
To do this, it seems like you have to first convert your data frame into an "xts" type:
library(xts)
xts_data <- xts(my_data[,-1], order.by=my_data[,1])
But this returns the following error:
Error in xts(my_data[, -1], order.by = my_data[, 1]) :
order.by requires an appropriate time-based object
This is preventing me from creating the final graph:
library(dygraphs)
dygraph(xts_data) %>% dyRangeSelector()
Can someone please show me how to fix this problem?
References: