ggvis
ggvis copied to clipboard
Error in Math.Date(x) : abs not defined for "Date" objects
In ggvis v0.4.1.9000 I have an error trying to plot a dataframe with Date object on 'x' axis.
Here is a simple example to reproduce:
library (ggvis)
df <- data.frame(
date = seq(as.Date("2015-01-01"), as.Date("2015-01-30"), by=1),
sessions = 1:30
)
df %>%
ggvis (~date, ~sessions) %>%
layer_bars()
This code generates an error:
Error in Math.Date(x) : abs not defined for "Date" objects
If I convert date object to character everything works fine.
Same issue experienced here:
http://stackoverflow.com/questions/31062750/ggvis-barchart-using-dates-as-x-axis
I fixed this by including the following in my code:
abs.Date <- function(x){x}
@ScottPayseur Would you mind expanding a bit on that previous comment please ?
@voxnonecho What @ScottPayseur means is that you can fix the error by manually defining the absolute value for date objects. Converting the date object to character is not needed (makes labeling your axis easier as well). Just copy and add this exact code at the start of your code:
abs.Date <- function(x){x}