stat_calendar_heatmap: Plots a calendar heatmap

Description Usage Arguments Aesthetics Data Tips Cosmetic Tips Also See Examples

View source: R/stat_calendar_heatmap.R

Description

A calendar heatmap provides context for weeks, and day of week and is a better way to visualise daily data than line charts.

Usage

1
2
stat_calendar_heatmap(mapping = NULL, data = NULL, show.legend = NA,
  inherit.aes = TRUE, na.rm = T, bandwidth = NULL, ...)

Arguments

mapping

mapping

data

df

show.legend

logical

inherit.aes

logical

na.rm

logical

bandwidth

bandwidth

...

more functions

Aesthetics

date, fill.

Data Tips

strftime can help extract the value of the year, week of year, and day of week from the date column. You might need to extract the year to facet multiple years as demonstrated in the example. This stat uses the following transformation to obtain the x and y coordinate to be used in the heatmap - data$x = 1 + as.integer(strftime(data$date, "%W")) data$y = as.integer(strftime(data$date, "%w")) data$y[data$y == 0L] = 7 data$y = 8 - data$y

Cosmetic Tips

The minimalist look can be achieved by appending the following chunk of code to the output object: + xlab(NULL) + ylab(NULL) + scale_fill_continuous(low = 'green', high = 'red') + theme( axis.text = element_blank(), axis.ticks = element_blank(), legend.position = 'none', strip.background = element_blank(), panel.background = element_blank(), panel.border = element_blank() )

Also See

ggplot_calendar_heatmap, a polished but less flexible alternative.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
{
library(ggplot2)
DailyData = data.frame(
      DateCol = seq(
         as.Date("1/01/2014", "%d/%m/%Y"),
         as.Date("31/12/2015", "%d/%m/%Y"),
         "days"
      ),
      ValueCol = runif(730)
   )
   DailyData$Year = strftime(DailyData$DateCol, "%Y")
ggplot(
   DailyData,
   aes(
      date = DateCol,
      fill = ValueCol
   )
) +
   stat_calendar_heatmap() +
   facet_wrap(~Year, ncol = 1)}

Example output

Loading required package: ggplot2

ggTimeSeries documentation built on Jan. 23, 2022, 5:07 p.m.