library(tidyverse)
Create a calendar
r
ggplot2
Y2024
This post is to create a calendar.
Intro
This post is to create a calendar to check when some events were more likely to occur.
Packages
Data
Create a data frame with a sequence of days
<- as.Date("2020-05-01")
firstday<- as.Date("2020-08-31")
lastday <- seq(firstday, lastday, by = "day")
days_seq <-as.data.frame(days_seq) days_df
Separate months and days
$month<-substr(days_df$days, start = 6, stop = 7)
days_df$day<-substr(days_df$days, start = 9, stop = 10) days_df
Add values
<-sample(1:7, 123, replace=TRUE)
my_values$events<-as.factor(my_values[1:123]) days_df
Separate months
<-days_df %>%
mayfilter(month=='05')
Create x and y axis
<-rep(c(1:7), times = 5)
calen_xs<-rep(c(5:1), each = 7) calen_ys
$calen_xs<-calen_xs[1:31]
may$calen_ys<-calen_ys[1:31] may
Select color palette
<- c("1" = '#577590',
my_palette "2" = '#43aa8b',
"3" = '#90be6d',
"4" = "#f9c74f",
"5" = "#f8961e",
"6" = "#f3722c",
"7" = "#f94144")
Plot
ggplot(may,aes(x=calen_xs,y=calen_ys,color=events))+
geom_point(size=25,shape=15)+
scale_x_continuous(limits=c(0.5,7.5))+
scale_y_continuous(limits=c(0.5,5.5))+
# remove background colors
theme_void()+
# adds texts
geom_text(aes(label=day),color='white') +
# sets the legend below
theme(legend.position = 'top')+
# lines the legend
guides(colour = guide_legend(override.aes = list(size=6),nrow = 1))+
# uses palette
scale_color_manual(name = "May no. events",values = my_palette)
I used this to see which dates there were more surveys occurring, hope it helps!