0

I'm plotting time series data that has an ISO8601 variable as the x-axis; however, having the labels as ISO8601 isn't very readable. What is the best way to retain the ISO8601 variable but display the labels as Day Month (i.e. 28 Jun)?

Here is what I currently have:

format(as.Date("2020-06-28"),"%d %b"))

But that means they now display in order like:

c("03 May","04 Jun", "06 May","07 Jun")

How can I get them to arrange in Date order?

timnus
  • 197
  • 10
  • 2
    Can you try `format(zoo::as.yearmon(as.Date("02-01-2018", format="%m-%d-%Y")), "%d %b")` – akrun Jun 28 '21 at 00:10
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jun 28 '21 at 00:12
  • 2
    You can change this in `scale_x_date` instead of `converting the `Date` class earlier – akrun Jun 28 '21 at 00:29
  • 2
    @timnus I would do `df1 %>% mutate(date = as.Date(date)) %>% arrange(date) %>%ggplot(....) + scale_x_date(date_labels = "%d %b")` – akrun Jun 28 '21 at 00:31
  • https://stackoverflow.com/questions/11748384/formatting-dates-on-x-axis-in-ggplot2 – Ronak Shah Jun 28 '21 at 03:35

0 Answers0