Skip to content
This repository has been archived by the owner on Nov 13, 2021. It is now read-only.

POSIXct and POSIXlt problem with the simple example #101

Open
SherryPan123 opened this issue Jul 11, 2018 · 3 comments
Open

POSIXct and POSIXlt problem with the simple example #101

SherryPan123 opened this issue Jul 11, 2018 · 3 comments

Comments

@SherryPan123
Copy link

After installing dependency and the project, I follow the simple example in README:

data(raw_data)
res = AnomalyDetectionTs(raw_data, max_anoms=0.02, direction='both', plot=TRUE)
res$plot

When I run res$plot, an error occurs:
Error: Column x is a date/time and must be stored as POSIXct, not POSIXlt
Does anyone know how to solve the problem? Thx

@supermdat
Copy link

I encountered something similar, and I believe the issue results from the latest update (effective 2018-07-03) of ggplot2 to version 3.0.0. Apparently, AnomalyDetection will internally convert to posixlt (see #29 comment on 2015-04-02), which ggplot2 doesn't work with in the latest version.

My short-term solution was to simply revert back to ggplot2 version 2.2.1
require(devtools) install_version("ggplot2", version = "2.2.1", repos = "http://cran.us.r-project.org")

An internal fix for posixlt conversion would be ideal. But as you saw, this only affects the plotting capability of AnomalyDetection. So if you wanted to use the latest ggplot2 version, you could also build the plot yourself.

@xvanausloos
Copy link

Thanks a lot: this fix works perfect for me.

@baztastic
Copy link

baztastic commented Jul 18, 2018

To expand on @supermdat 's answer, to work around this without downgrading ggplot2, use something like this:

data(raw_data)
raw_data$timestamp <- as.POSIXct(raw_data$timestamp)
res <- AnomalyDetectionTs(raw_data, max_anoms=0.02, direction='both', plot=FALSE)
res$anoms$timestamp <- as.POSIXct(res$anoms$timestamp)
ggplot(raw_data, aes(timestamp, count)) + 
  geom_line(data=raw_data, aes(timestamp, count), color='blue') + 
  geom_point(data=res$anoms, aes(timestamp, anoms), color='red')

Edit:
After writing this up, I found the more up-to-date fork of this package, that has solved a bunch of problems:
https://github.com/hrbrmstr/AnomalyDetection

PyRPy added a commit to PyRPy/TimeSeries_R that referenced this issue Dec 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants