r-lib / clock

A Date-Time Library for R
https://clock.r-lib.org
Other
97 stars 4 forks source link

Feature request: scales for ggplot2 #233

Open TimTaylor opened 3 years ago

TimTaylor commented 3 years ago

Is the plan to eventually be implementing scales for the various calendar objects (e.g. year_month_day)? I'm thinking maybe some sort of factor / categorical type scale would be appropriate depending on the precision?

mattwarkentin commented 1 year ago

I came here to ask the very same thing. It feels like this should work, but it doesn't. Would love for the addition of ggplot-friendly scales.

library(tidyverse)
library(clock)
library(nycflights13)

flights |> 
  select(year, month, day) |> 
  mutate(
    date = date_build(year, month, day),
    date = as_year_month_day(date),
    gp = calendar_group(date, 'day')
  ) |> 
  count(gp) |> 
  ggplot() +
  aes(gp, n) +
  geom_line()
#> Don't know how to automatically pick scale for object of type clock_year_month_day/clock_calendar/clock_rcrd/vctrs_rcrd/vctrs_vctr. Defaulting to continuous.
#> Error: Discrete value supplied to continuous scale

I was actually thinking it should be some sort of continuous type scale.