-
Notifications
You must be signed in to change notification settings - Fork 117
Closed
Description
This request is prompted by an issue in ggplot2::scale_*_time() described here. Essentially, calling scale_*_time() with the sec.axis argument set throws an error because scales::rescale() doesn't have hms or difftime methods:
library(hms)
library(ggplot2)
x_datetime <- as.POSIXct(paste0("2023-01-01 ", 0:23, ":00:00"))
x_time <- as_hms(x_datetime)
y <- sin(pi * 0:23 / 6)
dat <- data.frame(x_datetime, x_time, y)
ggplot(dat, aes(x_time, y)) +
geom_line() +
scale_x_time(sec.axis = sec_axis(trans = identity))
#> Error in UseMethod("rescale"): no applicable method for 'rescale' applied to an object of class "c('hms', 'difftime')"As @teunbrand demonstrated in the ggplot2 issue, defining a rescale.difftime() method would resolve the issue.
Metadata
Metadata
Assignees
Labels
No labels