Skip to content

Instantly share code, notes, and snippets.

@chichacha
Last active June 26, 2019 17:25
Show Gist options
  • Save chichacha/b206043078f46de191a3faa275e3070e to your computer and use it in GitHub Desktop.
Save chichacha/b206043078f46de191a3faa275e3070e to your computer and use it in GitHub Desktop.
2019 Calendar
library(tidyverse)
library(lubridate)
library(scales)
df <- tibble(
date = seq.Date(from=ymd("2019-01-01"),to=ymd("2019-12-31"),by="day"),
wkdy = wday(date,label=T),
mo = month(date,label=T),
mo.num = month(date,label=F),
day = day(date)
)
## Varitaion 1
df %>%
mutate(t=rescale(day,to=c(2*pi,0),from=c(1,36)),
x=cos(t + pi/2),
y=sin(t + pi/2))%>%
ggplot(aes(x=x,y=y,color=wkdy)) +
geom_path(size=0.5)+
geom_point(size=8) +
geom_text(aes(label=str_sub(wkdy,1,1)),color="#ffffff20",size=8) +
geom_text(aes(label=paste0(day)),size=4,color="#ffffff",family="Roboto Condensed",
fontface="bold") +
geom_text(aes(x=0,y=0,label=paste0(mo,"\n2019")),
family="Roboto Condensed", size=12,
data=. %>% filter(day==1), lineheight=0.8, vjust=0) +
geom_text(aes(x=0,y=0,label=paste0("\nstarts with\n",wday(date,label=T,abbr=F))),
family="Roboto Condensed", size=4,vjust=1,
data=. %>% filter(day==1), lineheight=0.8) +
coord_fixed() +
theme_void() +
expand_limits(c(0,0)) +
facet_wrap(~mo)+
scale_color_manual(values=c("#F44336","#FFC107","#FF9800","#00BCD4","#8BC34A","#9C27B0","#795548"), guide="none") +
theme(strip.text.x = element_text(size=0)) ## Removing Facet Label
ggsave("calendar/2019_Calendar.png", width=16, height=9)
## Variation 2
df %>%
mutate(t=rescale(day,to=c(2*pi,0),from=c(1,36)),
x=(mo.num+5)*cos(t + pi/2),
y=(mo.num+5)*sin(t + pi/2)) %>%
ggplot(aes(x=x,y=y,color=wkdy)) +
geom_path(size=0.1,alpha=0.2)+
geom_point(size=8) +
geom_text(aes(label=str_sub(wkdy,1,1)),color="#ffffff20",size=8) +
geom_text(aes(label=paste0(day)),size=4,color="#ffffff",family="Roboto Condensed",
fontface="bold") +
coord_fixed() +
theme_void() +
expand_limits(c(0,0)) +
scale_color_manual(values=c("#F44336","#FFC107","#FF9800","#00BCD4","#8BC34A","#9C27B0","#795548"), guide="none") +
annotate(geom="text", x=0,y=0,label="2019",family="Roboto Condensed",size=12,color="#00000050") +
annotate(geom="text", x=-0.5,y=c(6:17),label=month.abb,hjust=1,family="Roboto Condensed",
size=7,color="#33333390")
ggsave("calendar/2019_Calendar_2.png", width=16, height=16)
options("lubridate.week.start"=7) ##
## Variation 3
df %>%
mutate(weeknum = dense_rank(floor_date(date,"week"))) %>%
ggplot(aes(x=wkdy,y=weeknum)) +
geom_tile(aes(fill=wkdy),color="white",size=1,alpha=0.6) +
geom_text(aes(label=paste0(mo.num,"/",day,"\n",wkdy)),color="black",
family="Roboto Condensed",lineheight=0.8) +
scale_y_reverse() +
theme_void(base_family="Roboto Condensed") +
facet_wrap(~mo, scales="free") +
scale_fill_manual(values=c("#F44336","#FFC107","#FF9800","#00BCD4","#8BC34A","#9C27B0","#795548"), guide="none") +
theme(strip.text.x = element_text(size=15,family="Roboto Condensed",hjust=0))
ggsave("calendar/2019_Calendar_3.png",width=16, height=9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment