Skip to content

Instantly share code, notes, and snippets.

@infotroph
Created July 30, 2016 03:58
Show Gist options
  • Save infotroph/1db11d146dfb3d473151e6a8f9c0fca9 to your computer and use it in GitHub Desktop.
Save infotroph/1db11d146dfb3d473151e6a8f9c0fca9 to your computer and use it in GitHub Desktop.
Reversing date axes
a = data.frame(
date=as.Date(c("2016-07-31", "2016-08-01", "2016-08-03", "2016-08-04", "2016-08-10")),
x=rnorm(5))
# Origin to use might be OS-specific?
num2date = function(x){as.character(as.Date(x, origin="1970-01-01"))}
(ggplot(a, aes(as.numeric(date), x))
+geom_point()
+scale_x_reverse(labels=num2date)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment