Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add difftime and/or hms method to rescale() #382

Closed
ccsarapas opened this issue Mar 22, 2023 · 0 comments
Closed

add difftime and/or hms method to rescale() #382

ccsarapas opened this issue Mar 22, 2023 · 0 comments

Comments

@ccsarapas
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant