Created
October 14, 2019 12:14
-
-
Save MilesMcBain/2119b0912e7856b5ad1d4869a2e70aa3 to your computer and use it in GitHub Desktop.
date_facets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(lubridate) | |
epoch <- ymd("20080101") | |
date_frame <- | |
data.frame( | |
date = days(seq(1, 365 * 10, 1)) + epoch, | |
response = cumsum(rnorm(365 * 10)) | |
) | |
date_frame %>% | |
mutate( | |
graph_date = make_date( | |
2000, | |
month(date), | |
day(date) | |
), | |
year = year(date) | |
) %>% | |
ggplot(aes(x = graph_date, y = response)) + | |
geom_path() + | |
scale_x_date( | |
date_breaks = "1 month", | |
date_labels = "%b" | |
) + | |
labs( | |
title = "A plot I wish was easier", | |
subtitle = "maybe it is?" | |
) + | |
facet_wrap(~year, ncol = 1) + | |
theme_minimal() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment