# Minimal reproducible example (avoid using the name `df`, which masks stats::df)
set.seed(1)
dat <- data.frame(
date = seq(as.Date("2023-01-01"), by = "month", length.out = 24),
value = cumsum(rnorm(24))
)
library(ggplot2)
ggplot(dat, aes(date, value)) +
geom_line() +
scale_x_date(
date_labels = "%b\n%Y",
breaks = date_breaks_gg(n = 6, last = max(dat$date))
) +
labs(x = NULL, y = NULL)
Run the code above in your browser using DataLab