Git Product home page Git Product logo

ggcal's Introduction

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.