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

YearWeek and scale_x_yearweek with 1 year gaps lead to wrong x axis. #293

Open
USMortality opened this issue Dec 9, 2022 · 1 comment
Open

Comments

@USMortality
Copy link

USMortality commented Dec 9, 2022

YearWeek and scale_x_yearweek with 1 year gaps, lead to wrong x axis. See here in this example, 2020 is duplicated twice and every year, thereafter is offset by 1...

I think this has todo with the extra week 53 of 2020...
What can I do to fix this?

plot

df <- as_tibble(data.frame(
  x = seq(from = mdy("1/1/2019"), to = mdy("1/1/2022"), by = "week"),
  y = runif(157, min = 0, max = 25)
)) %>% mutate(x = yearweek(x))

ggplot(df, aes(x = x, y = y)) +
  geom_line(color = "#5383EC", linewidth = 1) +
  scale_x_yearweek(date_breaks = "1 year", date_labels = "%Y")
@USMortality
Copy link
Author

Workaround, use scale_x_date(date_labels = "%Y", breaks = "1 year") works fine.

df <- as_tibble(data.frame(
  x = seq(from = mdy("1/1/2019"), to = mdy("1/1/2022"), by = "week"),
  y = runif(157, min = 0, max = 25)
)) %>%
  mutate(x = yearweek(x)) %>%
  mutate(date = date(x))

ggplot(df, aes(x = date, y = y)) +
  geom_line(color = "#5383EC", linewidth = 1) +
  scale_x_date(date_labels = "%Y", breaks = "1 year")

plot

So IMO this shows, that there's clearly a bug in the scale_x_yearweek function. Using '52 weeks' as a workaround, appears to make it work, but obviously results in wrong ticks, as there are 53 weeks sometimes...

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

1 participant