Open USMortality opened 1 year ago
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")
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...
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?