One of the challenges in any data/analytics role is presenting your results in a way that clearly and simply communicates your findings. Sometimes a bar chart or scatter plot may not be enough and you need to get a little creative. In this example I am going to show you how to create a one month heatmap calendar chart using the calendR package.
For this example, we will be looking at the percentage of overall monthly sales that came from each day of the month in November. Presenting your data in this format may be useful if there were holidays, promotions, or any events of interest on certain days.
# Create sequence of dates for the month of November
dates <- seq.Date(from = as.Date("2023-11-01"), to = as.Date("2023-11-30"), by = 1)
# Create some sample sales data that will add up to 100% of overall sales
set.seed(1234)
sales_data <- rmultinom(1, 100, prob = rep.int(1 / 10, 30))/100
# Put it all into a dataframe
# Not necessary for this example.
# When working with live data you will likely be manipulating a dataframe so let's mimic that workflow!
df <- data.frame("cal_dates" = dates,
"sales_data" = sales_data)
Looking at the calendR documentation it can be easy to get overwhelmed as there are 30+ data fields. The majority of these can be left default since they mainly impact how you would like your calendar to display; such as the line size or colour.
In our example, to make the chart in the image above, we’re only going to utilize 13 of these fields!
# Load Packages Required
library(calendR)
library(tidyverse)
calendR(year = 2023,
month = 11,
special.days = df$sales_data, # decimal values we created for each day
special.col = "#56cc6b",
gradient = TRUE,
text.pos = day(df$cal_dates), # calendar days where we will be adding the below text
text = scales::percent(df$sales_data), # our decimals formatted as percentages for display purposes
text.col = "#000000",
title = "November Sales Recap",
subtitle = "Percentage of monthly sales coming from each day of the month",
days.col = "#000000",
weeknames.col = "#000000",
title.col = "#000000")
As we can see, creating this chart is actually fairly straightforward and doesn’t require too much code. One thing to note is that the data used for the gradient should be a decimal value between 0 and 1 as this tends to function better.
Using these charts for displaying daily percentages has been on of my favourite use cases!
If you would like to take this a step further, this process can be automated to generate a new calendar each month. One of the things I do in my current role is generating a monthly report that overviews the monthly performance of our Business Development Reps. An easy way to showcase their consistency and when we generated the most meetings for client-partners is creating a calendR chart. This allows us to easily see the percentage of daily bookings coming from each day of the month.