Package

calendR

Author

R CODER

Monthly calendar

You can create a monthly calendar in R with the calendR package. Specify the month in the month argument (from 1 to 12).

# install.packages("calendR")
library(calendR)

# Specify the year and the month
calendR(year = 2022,
        month = 3)

Monthly calendar in ggplot2

Adding texts

The function allows you to add text to some days. For that purpose you can pass a vector with the text to text argument and specify its position (the days) with text.pos.

Adding text to the calendar

# install.packages("calendR")
library(calendR)

# Add text to the days
calendR(year = 2021,
        month = 3,
        text = c("Event 1", "Event 2"),
        text.pos = c(4, 8),
        text.col = "blue")

Adding events

Moreover, you can colorize some days to indicate some event. In this scenario you will need to create a vector of NA and fill it with the events in order to pass it to special.days argument. The colors can be customized with special.cols and the legend position with legend.pos.

# install.packages("calendR")
library(calendR)

# Vector of NA which length is
# the number of days of the month
fills <- rep(NA, 31)

# Add the events to the desired days
fills[c(4, 10, 15, 22)] <- "Event 1"
fills[c(1, 5, 17, 30)] <- "Event 2"

# Specify the year
calendR(year = 2022,
        month = 3,
        special.days = fills,
        special.col = 3:4,
        legend.pos = "bottom")

Adding events to a monthly calendar

Further customization

You can also customize more arguments, such as the start of the week, the background color or the line type of the calendar, as shown in the example below. Recall to type ?calendR for a full list or arguments with their corresponding description.

Customization of the monthly calendar in R

# install.packages("calendR")
library(calendR)

calendR(month = 7,
        year = 2022, 
        start = "M",               # Start on Monday
        special.days = "weekend",  # Colorize weekends
        special.col = "lightblue", # Weekends color
        bg.col = "#f7f7f7",        # Background color
        lty = 2)                   # Line type

See also