Last active
April 23, 2020 15:31
-
-
Save ryanburge/3ab673d6a02dc9dfb35e3f5715b19384 to your computer and use it in GitHub Desktop.
Making a calendar
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
## Packages ## | |
library(socsci) #remotes::install_github("ryanburge/socsci") | |
library(ggcal) #remotes::install_github("jayjacobs/ggcal") | |
library(showtext) | |
library(ggthemes) | |
library(ggsci) | |
library(lubridate) | |
## My theme function ### | |
theme_gg <- function(fff, base_size = 14, base_family = "font", legend = FALSE){ | |
font_add_google(fff, "font") | |
showtext_auto() | |
showtext_opts(dpi = 300) | |
if(legend == TRUE){ | |
theme_minimal() + | |
theme(legend.position = "bottom") + | |
theme(legend.title = element_blank()) + | |
theme(text=element_text(size=14, family="font")) | |
} | |
else{ | |
theme_minimal() + | |
theme(legend.position = "none") + | |
theme(legend.title = element_blank()) + | |
theme(text=element_text(size=14, family="font")) | |
} | |
} | |
### Use the command line in Windows to list all the dates ### | |
## Mine is on my E Drive | |
dir /t:W E: | |
## Copy the output into a csv file #### | |
## Read it in ### | |
date <- read_csv("D://dates.csv") | |
## Extract the date, which is the first word ### | |
new <- word(date$date, 1) | |
## Count the graphs per date #### | |
df <- as_tibble(new) %>% ct(value) | |
### Make it into a date #### | |
df <- df %>% | |
mutate(day = mdy(.$value)) %>% | |
na.omit() | |
## Clean things up #### | |
df <- df %>% | |
arrange(day) | |
df = df[-1,] | |
df <- df %>% | |
filter(n <= 10) | |
## Make the calendar #### | |
gg <- ggcal(df$day, df$n) | |
gg + | |
theme_gg("Abel") + | |
theme(legend.position = c(.75, .1), legend.direction = "horizontal") + | |
theme(axis.title.x=element_blank(), | |
axis.text.x=element_blank(), | |
axis.ticks.x=element_blank()) + | |
theme(axis.title.y=element_blank(), | |
axis.text.y=element_blank(), | |
axis.ticks.y=element_blank()) + | |
scale_fill_gradient2(low="#fdbb2d", mid="#b21f1f", high="#1a2a6c", midpoint=2, na.value = "gray95") + | |
labs(x = "", y ="", title = "Graphs Made Per Day", caption = "@ryanburge") + | |
ggsave("E://cal_try.png", type = "cairo-png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment