If I have a data.frame df
library(lubridate) library(ggplot2) library(dplyr) day.start = today() df = data.frame(date = seq.Date(from = today() - days(10), to = today() + days(10), 'day')) df$day.idx = as.numeric(df$date - day.start + 1) df$day.idx = ifelse(df$day.idx < 1, df$day.idx + nrow(df), df$day.idx) df = df %>% arrange(day.idx) df$value = 1:nrow(df) I can plot the values vs dates like this
ggplot(df) + geom_line(aes(x = date, y = value)) However I want to make an adjustment for a custom year so I want the x axis to start at today's date.
## I want the x axis to start with day.start df = df %>% mutate(date = factor(date, levels = as.character(df$date))) ## how to change x axis to behave like dates again? ggplot(df) + geom_point(aes(x = date, y = value)) + geom_line(aes(x = date, y = value)) ## where is this line? So the second plot looks better but how do I format the x-axis to look like (nicely spaced) dates again?




today()is from thelubridatepackage, don't forget that for your example.