My (minimal reproducible) code shows two possibilities for scale_x_datetime.
Without the lables specifier I get tick labels in the format yyyy-mm-dd. I don’t want the year in the tick label, as the year is used in the start and end dates in the title.
However, when I use the labels specifier the tick labels show the last day of the month.
How do I get the tick labels, without the year, at the first day of the month.
Thank you.
library(ggplot2)
library(scales)
mydata <- read.table(header = TRUE, text = "
dates values
2022-12-03 5
2023-03-02 0
")
plottib <- tibble(mydata) %>%
mutate(dates = as.POSIXct(dates,format="%Y-%m-%d") )
start_date <- min(mydata$dates)
end_date <- max(mydata$dates)
gp <- ggplot( plottib , aes( x=dates, y=values )) +
geom_point() +
labs(title = paste("From", start_date, 'to', end_date, sep=' ') ) +
scale_x_datetime(date_breaks = "1 month") `a`
# scale_x_datetime(date_breaks = "1 month", labels = date_format("%d %b") )
gp