I can't add an abline to my ggplotly graph if it's set for a date. Reading the error, this seems like a Plotly issue, but maybe I'm wrong, or maybe there's a workaround. Is there a way to add a line to chart if the line is defined by a date?
require(tidyverse)
require(plotly)
rev <- tibble(date=as.Date(c("2019-01-01","2019-01-02","2019-01-03")),
rev=c(100,200,150))
rev
rev_plot <- ggplot(data=rev, aes(x=date, y=rev, group=1)) +
geom_line() +
geom_vline(xintercept = as.Date('2019-01-02'))
# geom_hline(yintercept = 200) ### an integer abline works fine
# Plot it - works fine with ggplot2
rev_plot
# With Plotly, it fails
ggplotly(rev_plot)
ERROR Error in Ops.Date(z[[xy]], 86400000): * not defined for “Date” objects
Error in Ops.Date(z[[xy]], 86400000): * not defined for “Date” objects
Traceback:
- ggplotly(rev_plot)
- ggplotly.ggplot(rev_plot)
- gg2list(p, width = width, height = height, tooltip = tooltip,
. dynamicTicks = dynamicTicks, layerData = layerData, originalData = originalData,
. source = source, ...)- gg2list_legacy(p, width = width, height = height, tooltip = tooltip,
. layerData = layerData, originalData = originalData, source = source,
. ...)- lapply(traces, function(z) {
. z[[xy]] <- z[[xy]] * 86400000
. z
. })- FUN(X[[i]], ...)
- Ops.Date(z[[xy]], 86400000)
- stop(gettextf(“%s not defined for \“Date\” objects”, .Generic),
. domain = NA)