2020-03-13

How to create a calendar heatmap in R


Problem

We want to create a calendar heatmap for a time series in R.

Solution

First we run the calendarHeat function created by Paul Bleicher to display calendar heatmaps. Secondly we create some random time series data. Finally we plot the time series in two palettes.

library(tidyverse)
# Random data
set.seed(2015)
df <-
  data.frame(dates = sample(seq(
    as.Date('2018-01-01'),
    as.Date('2020-12-31'),
    by = "day"
  ), 1000))
df <- df %>% mutate(sessions = floor(runif(nrow(.), 1, 101)) )
# Two calendar with different palettes
calendarHeat(df$dates, df$sessions, varname = "Sessions")
calendarHeat(df$dates, df$sessions, varname = "Sessions", ncolors = 99, color = "r2b" )

Results

Related posts

No hay comentarios:

Publicar un comentario

Nube de datos