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

Adding date_breaks to scale_*_time #4335

Open
llrs opened this issue Jan 31, 2021 · 2 comments · May be fixed by #6282
Open

Adding date_breaks to scale_*_time #4335

llrs opened this issue Jan 31, 2021 · 2 comments · May be fixed by #6282
Labels
feature a feature request or enhancement scales 🐍

Comments

@llrs
Copy link
Contributor

llrs commented Jan 31, 2021

I am working with a dataset where there are huge time differences.
If I use scale_*_time I cannot convert those labels to a more meaningful label such as 1 week, 2 weeks... as it can be done with scale_*_date*. Could it be possible to add the date_breaks argument to scale_*_time (or something similar)?

library("hms")
library("ggplot2")
data.frame(diff = as_hms(c(1850000, 800)), time = rep(Sys.time(), 2))
ggplot(df) +
    geom_point(aes(time, diff)) 

This would make it easier to interpret the plots.


Couldn't find any issue related to this

@thomasp85 thomasp85 added feature a feature request or enhancement scales 🐍 labels Mar 24, 2021
@teunbrand
Copy link
Collaborator

I think the breaks_width() and label_time() function from {scales} are already flexible enough to handle such cases, or am I missing something here?

library(hms)
library(ggplot2
library(scales)

df <- data.frame(diff = as_hms(c(1850000, 800)), time = rep(Sys.time(), 2))
p <- ggplot(df) +
  geom_point(aes(time, diff))
p + scale_y_time(
    name   = "Week",
    breaks = breaks_width("1 week"),
    labels = label_time("%W")
  )

p + scale_y_time(
  name = "Days",
  breaks = breaks_width("4 days"),
  labels = label_time("%j")
)

Created on 2022-12-03 by the reprex package (v2.0.1)

@llrs
Copy link
Contributor Author

llrs commented Dec 5, 2022

I was not aware of this functions when I opened the issue, so this might solve the inmediat problem. However, it wouldn't be consistent with other time related scales_*, which simply use date_breaks = "1 week" and the rest is done by ggplot2 itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement scales 🐍
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants