Skip to content

Do not censor date breaks - #5636

Merged
teunbrand merged 1 commit into
tidyverse:rc/3.5.0from
teunbrand:date_censoring
Jan 12, 2024
Merged

teunbrand merged 1 commit into
tidyverse:rc/3.5.0from
teunbrand:date_censoring

Conversation

@teunbrand

@teunbrand teunbrand commented Jan 9, 2024 •

Copy link
Copy Markdown
Collaborator

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 requested a review from thomasp85 January 9, 2024 08:50
@teunbrand
teunbrand changed the base branch from main to rc/3.5.0 January 9, 2024 08:50

@thomasp85 thomasp85 left a comment

Copy link
Copy Markdown
Member

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
@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