Skip to content

Feature request: could colouring of date, datetime and time variables be supported more completely? #4982

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

Closed
davidhodge931 opened this issue Sep 9, 2022 · 3 comments

Comments

@davidhodge931
Copy link

At present, there are only scale_colour_date and scale_colour_datetime functions available for modifying date, datetime and time colours. These appear to be equivalent to scale_colour_gradient.

This means that it is not possible to create colour steps with date, datetime or time variables.

Not is it possible to use the methods and colours/values arguments of the scale_colour_gradientn function.

It would be awesome if date, datetime and time colouring were supported more completely in this way!

@teunbrand
Copy link
Collaborator

teunbrand commented Dec 9, 2022

For the continuous colour palettes, you can get pretty far with trans = "date" or trans = "time" (see examples below). Is there a particular thing that you're missing in date scales that we're unable to do with supplying the date transformation to continuous scales?

library(ggplot2)

ggplot(economics, aes(date, unemploy)) +
  geom_line(aes(colour = date)) +
  scale_colour_gradientn(
    colours = rainbow(10),
    trans = "date",
    breaks = scales::breaks_width("10 years")
  )

df <- data.frame(
  x = Sys.time() + seq(0, 2e6, length.out = 20),
  y = rnorm(20)
)

ggplot(df, aes(x, y)) +
  geom_line(aes(colour = x)) +
  scale_colour_viridis_c(
    trans = "time",
    breaks = scales::breaks_width("5 days")
  )

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

The binned version of scales have separate issues, because binning arithmetic is currently incompatible with dates.

@davidhodge931
Copy link
Author

Thanks @teunbrand. I was not aware that you could do this. Yes, that would allow you to do most things other than apply another trans to the date or time colour variable

@teunbrand
Copy link
Collaborator

Due to #5103 having been merged, I think there are now a sufficient amount of options to use date/time variables in non-position scales. Therefore, I'll thank you for this suggestion and hope you have enough tools to make this work.

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

2 participants