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

Do not censor date breaks #5636

Merged
merged 1 commit into from
Jan 12, 2024
Merged

Conversation

teunbrand
Copy link
Collaborator

@teunbrand teunbrand commented Jan 9, 2024

This PR to the RC aims to fix a bug uncovered during reverse dependency checks.

Briefly, in #5569 we moved the censoring of breaks from the scales to the guides.
ScaleContinuousDate was overlooked, since it didn't do the usual scales::censor().
In turn, the scale could censor a break, which may result in mismatched labels/breaks.
In this PR, we remove the scale's censoring, because we handle that elsewhere now.

To reproduce issue with current RC:

library(ggplot2)

limits <- as.Date(c("2000-01-01", "2010-01-01"))

df <- data.frame(x = limits, y = 1:2)

ggplot(df, aes(x, y)) +
  geom_point() +
  scale_x_date(
    breaks = as.Date(c("2000-01-01", "2011-01-01")), #2nd breaks is oob
    labels = c("2000", "2011")
  )
#> Error in `scale_x_date()`:
#> ! `breaks` and `labels` have different lengths.

With this PR, the out-of-bounds break simply isn't rendered.

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

ggplot(df, aes(x, y)) +
  geom_point() +
  scale_x_date(
    breaks = as.Date(c("2000-01-01", "2011-01-01")),
    labels = c("2000", "2011")
  )

Created on 2024-01-09 with reprex v2.0.2

@teunbrand teunbrand added this to the ggplot2 3.5.0 milestone Jan 9, 2024
@teunbrand teunbrand changed the base branch from main to rc/3.5.0 January 9, 2024 08:50
Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand teunbrand merged commit 8cbc148 into tidyverse:rc/3.5.0 Jan 12, 2024
12 checks passed
@teunbrand teunbrand deleted the date_censoring branch January 12, 2024 09:25
thomasp85 pushed a commit that referenced this pull request Feb 23, 2024
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

Successfully merging this pull request may close these issues.

2 participants