How to create a heatmap for a calendar?

Asked

Viewed 71 times

5

One of the graphs I find most interesting is called, in English, heatmap Calendar. Perhaps its most common application is in github, that displays our collaborations in the last year with the chart below:

Heatmap calendar no github

How is it possible to create a visualization like this in R? Below I provide the values of the Bovespa index in the last 5 years for those who want to contribute a response.

library(BatchGetSymbols)

bvsp <- BatchGetSymbols('^BVSP', 
                        first.date = as.Date("2015-01-01"), 
                        last.date = as.Date("2019-12-31"))
  • Maybe the package devtools::install_github("jayjacobs/ggcal") can help. Or this post from R-bloggers.

  • The name of this type of graphic "waffle Chart" or square pizza chart. I won’t be able to respond quickly, but these projects should help: hrbrmstr/waffle and liamgilbey/ggwaffle

  • The "challenge" of the case will be to expand the data to 365 days of the year and then plot the chart

1 answer

4


The package ggTimeSeries has the function ggplot_calendar_heatmap for that reason:

library(ggTimeSeries)

dados <- data.frame(
  data = seq(as.Date("1/01/2019", "%d/%m/%Y"), as.Date("31/12/2019", "%d/%m/%Y"), "days"),
  valor = sample(1:5, 730, replace = TRUE))

ggplot_calendar_heatmap(dados, "data", "valor",
                        dayBorderSize = .5, dayBorderColour = "gray",
                        monthBorderSize = .5) +
  scale_fill_gradient(NULL,
                      low = "lightyellow", high = "darkgreen",
                      guide = "legend") +
  theme(legend.position = "bottom") +
  xlab(NULL) +
  ylab(NULL)

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.