-
Notifications
You must be signed in to change notification settings - Fork 25
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
Allow x_axis_date_format argument to ptd_create_ggplot() to accept a function not just a string #197
Comments
We should probably just switch from using the date_labels to labels argument if labels accepts both strings and function? |
I think there's a good reason why Hadley created a separate date_labels argument, and I suspect that reason is that it is configured to handle I guess we could implement a logic where if it's a string we assume it's a date format string and pass it to You can still use a function if you need to, by passing the ptd output on into |
What use-case do you have in mind @francisbarton? What would this change enable? |
This actually came from a discussion with a colleague of ours at NUH. They wanted the x axis to display something like "2023-Q3"; that is, quarters (with Using a function like quarter_label <- function(x) {
q <- lubridate::quarter(x)
y <- lubridate::year(x)
paste0(y, "-Q", q)
} is what you need. Currently you can do this by: data |>
ptd_spc(...) |>
ptd_create_ggplot(...) +
ggplot2::scale_x_datetime(labels = quarter_label) - and that might be a good enough workaround for now. |
Currently ptd_create_ggplot passes
x_axis_date_format
to thedate_labels
argument ofggplot2::scale_x_datetime()
, which only accepts a format string.The
labels
argument ofggplot2::scale_x_datetime()
will accept a function or a string (or a vector).I wonder if we could build in some logic to PTD that would handle a function if supplied to
x_axis_date_format
, and pass this tolabels
instead ofdate_labels
.I haven't done any work on trying to make this work, just asking the question for now.
The text was updated successfully, but these errors were encountered: