rggplot2julian-date

How can I make the x-axis values more visible?


I have this graph with the x-axis showing Julian dates across a single year. I would like to condense the x-axis a bit more and make it for legible, but I am unsure how. Maybe increasing the Julian date by increments of 2 or 3 days? I would like to prevent losing as much information from the graph as possible. So I converted a date and time column with the format `YYYY-MM-DD HH:MM:SS' to a POSIXct then I changed the format of the column to Julian Dates.

ind_steps$t2 <- format(as.POSIXct(ind_steps$t2),"%y%j") 

I had tried to turn the x-axis label by 90 degrees to see if that would make it more legible, but it didn't help very much.

plot_list[[i]]  <- ggplot(ind_steps, aes(x = t2, y = NSD)) + 
  geom_line() + theme_bw() +
  ggtitle(random_tables[i]) +
  theme(axis.text.x = element_text(angle = 90)) +
}

enter image description here


Solution

  • The line of code below might help you. It assumes your date field is year-month-day; and labels the x-axis with a two year interval.

    scale_x_date(date_breaks = "2 year", date_labels = "%Y")