Welcome to my Code-Through

This code-through is an introduction to the calendR package. The calendR package helps in making completely adjustable/customizable ggplot2 calendar plots with one function only. This package was created by José Carlos Soage González and Natalia Pérez Veiga. In this code-through, we will create ready to print yearly and monthly calendar plots in R and we will also view daily values of stock prices over the year using a calendar! You can read more about the package here

I found this package to be interesting because I always like to manage my schedule, time and activities, and after I found this package I can customize my own calendar in R!

You can use the below December Calendar to plan your month. Merry Christmas!


Installation of the calendR package


Yearly Calendar

Basic Yearly Calendar

We started by calling the function calendR which will print for us the current yearly calendar. This package is simple as it only contains one function which is the calendR function. In the function we have many arguments that will help us customize our Calendar.However, If no argument is specified the function will return the current year in landscape orientation.


Customized Yearly Calendar

Here I will customize my yearly calendar .

I chose the below arguments:

mbg.col: Background color for month names(I chose 15 which represents the color yellow). The default is the color white.

months.col: Text color of the month names

start: This specifies on what day you would like your calendar to start . I chose M which specifies that I want my calendar to start on Monday.If not specified,the week starts on Sunday(Default).

special.days: This will help me choose the special days that I want highlighted in my calendar. In the example below I chose weekend however If you would like to color specific days then you have to specify the corresponding day of the year (from 1 to 365 or 366).

special.col: Color for the days indicated in special.days.

months.pos: specifies alignment of month names (eg. 0 will align month names to the left, 1 will align month names to the right, and 0.5 is the default which will align the months to the middle)

orientation: We have two orientations (Landscape and Portrait).The default orientation is landscape.

weeknames: Character vector with the names of the days of the week starting on Monday. By default they will be in the system locale.We can rename days of the week(I chose to abbreviate them).

bg.img:Character string containing the URL or the local directory of a image to be used as background.

If you are interested in saving this calendar , you can set the argument pdf=TRUE to save the calendars in a ready to print PDF format (A4 format by default). You can also set papersize = "A6" or choose any other papersize.


Monthly Calendar

Basic Monthly Calendar

Here we specified the month of December.


Customized monthly Calendar

You can find a description of the arguments in the below comments. note : You can only add text in monthly calendars.

Our December Calender is ready!


Calendar Heat map in R

Calendars are not only useful for personal use but are also useful to track changes over time. In the below code , I do not use the calendR function , instead I loaded the function calendarHeat. Let’s use the calendarHeat function to understand how stock prices change over the year!

The R code for calendarHeat() can be downloaded through Paul Bleicher’s Github page.

calendarHeat() makes the process much easier! We will call the function and specify the below arguments.

  1. date : Dates for which the data needs to be plotted.

  2. values: Values associated with those dates.

  3. color: The color palette. Default is r2g (red to green). You can create your own palette by defining a vector as shown below.

  4. ncolors: Number of colors for the heatmap

  5. varname: Title for the chart

If we want to view daily values for the whole year, then Calendar Heat maps are especially useful. We can obtain the Moderna stock prices using the tidyquant package.

I chose Moderna Inc to view how the stock prices changed over time. Upon the release of the news in November that the mRNA-1273 met its primary efficacy endpoint in the first interim analysis of the Phase 3 COVE study with a vaccine efficacy of 94.5%, the stock prices went up!


Conclusion

I really enjoyed creating calendars and customising them . I hope you did too! In the above tutorial, we went through steps of creating a yearly calendar and adding events to certain dates , then we created a customized december calendar that you can use for this month . Finally , we created a calendar heat map that displays stock prices for Moderna Inc to show that calendars can be also useful if we are interested in visualising time-series data.