Generate simple calendar plots using ggplot2
Clone or download
jayjacobs jayjacobs
jayjacobs and jayjacobs updated readme for multi-year plot
Latest commit ab1a85a Mar 18, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R initial commit Mar 18, 2017
README_files/figure-markdown_github updated readme for multi-year plot Mar 18, 2017
man initial commit Mar 18, 2017
.Rbuildignore added readme Mar 18, 2017
.gitignore added readme Mar 18, 2017
DESCRIPTION initial commit Mar 18, 2017
LICENSE Initial commit Mar 18, 2017
NAMESPACE initial commit Mar 18, 2017
README.Rmd updated readme for multi-year plot Mar 18, 2017
README.md updated readme for multi-year plot Mar 18, 2017
ggcal.Rproj initial commit Mar 18, 2017

README.md

ggcal is a simple package to generate a familiar calendar plot from a vector of dates and fill values.

Installation

devtools::install_github("jayjacobs/ggcal")

Generating a simple calendar plot

library(ggplot2)
library(ggcal)

mydate <- seq(as.Date("2017-02-01"), as.Date("2017-07-22"), by="1 day")
myfills <- rnorm(length(mydate))

print(ggcal(mydate, myfills))

The function returns as base ggplot object, which can be modified with scale_fill_*

gg <- ggcal(mydate, myfills) +
  scale_fill_gradient2(low="#4575b4", mid="#ffffbf", high="#d73027", midpoint=0)

print(gg)

Notice how the last few days in July are missing in the original data and are set to a dark gray by default. This can be overridden in the scale_fill_* function.

mydate2 <- sample(mydate, 100) 
myfills2 <- rnorm(length(mydate2))

gg <- ggcal(mydate2, myfills2) +
  scale_fill_gradient2(low="#4575b4", mid="#ffffbf", high="#d73027", midpoint=0,
                       na.value="gray95")

print(gg)

The fill values also do not have to be a continuous variable.

mydate <- seq(as.Date("2017-02-01"), as.Date("2017-07-31"), by="1 day")
myfills <- ifelse(format(mydate, "%w") %in% c(0,6), "weekend" ,"weekday")

ggcal(mydate, myfills) + scale_fill_manual(values=c("weekday"="steelblue", "weekend"="lightsteelblue"))

This will also span multiple years...

mydate <- seq(as.Date("2016-09-01"), as.Date("2017-02-28"), by="1 day")
myfills <- rnorm(length(mydate))

ggcal(mydate, myfills) + 
    scale_fill_gradient2(low="#4575b4", mid="#ffffbf", high="#d73027", midpoint=0)