Giter Site home page Giter Site logo

hathawayj / calheatmapr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from durtal/calheatmapr

0.0 1.0 0.0 1.88 MB

R package for using the cal-heatmap Javascript library

Home Page: http://hathawayj.github.io/calheatmapR/

R 5.66% JavaScript 93.01% CSS 1.33%

calheatmapr's Introduction

calheatmapR

I have forked this from durtal's repository

The calheatmapR package is an R interface for the cal-heatmap Javascript charting library, which is used to

create calendar heatmaps to help visualise time series data, a la github contribution graph

The package owes everything to the creators of the R package htmlwidgets (repo), Ramnath Vaidyanathan and JJ Alaire, as well as the RStudio team. And to @timelyportfolio who has created a huge amount of htmlwidgets, be sure to check out his site buildingwidgets. This is my first htmlwidget package and at the moment it is a bit limited and doesn't replicate everything that the Javascript library does.

There are options of the cal-heatmap Javascript library that aren't yet available in this package, these are the options which add more interactive elements to a calendar heatmap. Things such as next and previous to scroll through the timeseries, or the onClick event, the majority can be found in the Methods and Events sections on the cal-heatmap homepage.

Help pages can be found here, as mentioned in those pages, I am unsure how a calheatmapR plot will work in a shiny app in which the data is updated.

Installation

The calheatmapR package is only available on github, so to install you will need the devtools package installed

devtools::install_github(repo = "hathawayj/calheatmapR")

Data

At the moment the data to be plotted must be a list of numeric values, the names of which should be timestamps (in seconds), see the Data Format section on the cal-heatmap page. This list is converted to JSON, an example list is seen below, which corresponds to 2001-01-01 with a value of 1, thru to 2001-01-03 with a value of 100.

$`978307200`
[1] 1

$`978393600`
[1] 10

$`978480000`
[1] 100

The following two lines shows how to calculate a timestamp in R, it is perhaps a little crude and other simpler solutions are probably available, but I am unaware of them, so suggestions would be welcome

as.POSIXct("2001-01-01")
[1] "2001-01-01 GMT"

as.numeric(as.POSIXct("2001-01-01"))
[1] 978307200

Therefore to create the list from above:

demoData = list(1, 10, 100)
names(demoData) <- c(as.numeric(as.POSIXct("2001-01-01")), as.numeric(as.POSIXct("2001-01-02")), as.numeric(as.POSIXct("2001-01-03")))

Usage

The calheatmapR function initialises a cal-heatmap plot, with default options, which produces a plot showing values per minute for 12 hours.

calheatmapR(data = demoData)

Following a similar convention to the dygraphs package developed by RStudio, the calheatmapR package allows further customisation of a calendar heatmap; this customisation is, more often than not, required.

There are three supplementary functions to customise a plot, these are chDomain, chLegend and chLabel, these functions are well documented, and the argument names are the same as those used by the Javascript library. The code below shows the use of the more important chDomain arguments, namely domain, subDomain and start, the resulting plot follows, and displays days within months, starting in December 2012, for 5 months.

calheatmapR(data = demoData) %>%
    chDomain(domain = "month", subDomain = "day", start = "2000-12-01", range = 5)

calheatmapr's People

Contributors

durtal avatar hathawayj avatar

Watchers

 avatar

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.