Description
Hi folks. It seems various people have been confounded by trying to reverse the order of date scales in ggplot2. The scale_x_date family of functions is great, but their presence seems to have made reversing scales even less intuitive/possible.
By way of example, I convert dates into yeardays (1:366) and project on the Y axis, with values going from bottom to top, Jan to Dec (various irrelevant code lines removed e.g. theme, title etc):
mydata %<>% mutate(Day = yday(Date))
ggplot(mydata, aes(x = toppid, y = as.Date(Day, origin = as.Date("2018-01-01")))) +
geom_point(aes(colour = MarineArea), size = 0.25) +
facet_wrap(.~Stock, scales = "free") +
scale_y_date(date_breaks = "1 month", date_labels = "%b")
It occurred to me that I could reverse the data themselves for Day:
mydata$Day2 <- 367 - mydata$Day
But this only affects the plotted points, not the scale.
Given the existing solutions to this issue seem hacky, if applicable to the above formulation at all, is there any chance that a future release could see a reverse
or trans
parameter added into scale_x/y_date
?
Thanks in advance.