klaukh / d3heatmap

A D3.js-based heatmap htmlwidget for R

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This is a fork of d3Heatmap for purposes of incorporating community PRs and issues logged in the main repo.

As the main repo is not currently being actively maintained, feel free to offer PRs and issues here. I actively use heatmaps in my projects and like this implementation over other non-d3 based heatmaps, so I will be active in maintaining this repo.

Please note, my time is constrained (like most of us), so I will have limited time to implement major new features on my own; I appreciate all assistance from the community for processing issues and new features.

In the future I hope to offer an updated version back to Rstudio for pulling into the main repo, and then hopefully an udpated CRAN submission.


__2018-02-24 Gadget

An shiny gadget coupled with an S4 class that provides print() and save() methods. Gadget takes normal d3heatmap inputs and allows for interactive adjustment of the heatmap. Gadget allows for filtering rows and columns, and also a dynamic filter to interatively subset the entire underlying data set. Saving the gadget to an object generates the S4 class that contains the heatmap, data, filter, and settings. Passing the gadget back into the function d3heatmapGadget(gadget) starts the user at the last state of the gadget.

gadget <- d3heatmapGadget(mtcars, col = 'blues')
print(gadget)
save(gadget, file = "heatmap.html")
gadget <- d3heatmapGadget(gadget)
    

2018-01-13 Side colors

Based on example contributions and forks from several people, the side colors components of heatmap.2 and heatmap.3 have been added! Functionality includes color labels, axis labels for the color sections, and hover info. Further alignment of the old API parameters to heatmap.2 and heatmap.3, plus heatmap.2/3 and the modern API were implemented for side colors. the Readme, package news and examples were also updated.

2017-12-17 New API!!

The master branch now includes a newer, modern API, motivated by the main d3heatmap fork's desire for a new API and inspired by the API of the dygraphs package produced by RStudio. The new API takes advantage of magrittr piping and offers smaller functions to modify selected portions of the heatmap. I have conducted good, but by no means exhaustive, testing... so feel free to poke around, find bugs, and open up issues or PRs for them.


D3 Heatmap for R

This is an R package that implements a heatmap htmlwidget. It has the following features:

  • Highlight rows/columns by clicking axis labels
  • Click and drag over colormap to zoom in (click on colormap to zoom out)
  • Optional clustering and dendrograms, courtesy of base::heatmap

Example

Installation

To install:

if (!require("devtools")) install.packages("devtools")
devtools::install_github("rstudio/d3heatmap")

Usage

Like any htmlwidget, you can visualize a d3 heatmap directly from the R console:

library(d3heatmap)
d3heatmap(mtcars, scale = "column", colors = "Spectral")

You can also include them in R Markdown chunks, or use them in Shiny applications with the d3heatmapOutput and renderD3heatmap functions.

See ?d3heatmap for options.

Modern API

Inspired by dygraphs and able to leverage magrittr, the new API provides a second method for invoking d3heatmap and integrating with Shiny apps, modules, and gadgets! Examples:

library(d3heatmap)
library(magrittr)

d3heatmap(mtcars, dendrogram = 'none', key = TRUE, col = 'RdYlGn',
          scale = 'column', key.title = "Legend", print.values = T,
          notecol = 'white') %>% 
  hmAxis("x", title = "test", location = 'bottom') %>% 
  hmAxis("y", title = "test", location = 'left') %>% 
  hmCells(font.size = 8, color = 'blue') %>% 
  hmLegend(show = T, title = "Title", location = "tl")
  

Side colors

library(d3heatmap)
library(magrittr)

rsc<-matrix(rep_len(c('good', 'bad', 'ugly'), length.out = 64), ncol = 2)
rsccols<-c('red', 'white', 'blue')
rscnames <- c('Row 1', 'Row 2')

csc<-matrix(rep_len(c('first', 'second', 'third', 'fourth', 'fifth'), length.out = 33), nrow = 3)
csccols<-c('orange', 'blue', 'grey', 'green', 'red')
cscnames <- c('Column 1', 'Column 2', 'Column 3')

library(d3heatmap)
d3heatmap(mtcars,
          key = TRUE, scale = 'column', 
          key.title = "Legend", 
          col = 'RdYlGn',
          srtCol = 30, 
          breaks = 8,
          xlab = 'test',
          ylab = 'TEST',
          print.values = T,
          density.info = 'histogram',
          denscol = 'grey',
          sideCol = 3,
          sideRow = 4,
          RowSideColors = rsc,
          ColSideColors = csc,
          RowColorsPalette = rsccols,
          ColColorsPalette = csccols,
          RowColorsNames = rscnames,
          ColColorsNames = cscnames)

## using the modern API:

d3heatmap(mtcars, key = TRUE, scale = 'none') %>% 
  hmSideColors(axis = 'column', side.colors = csc,
    palette = csccols, names = cscnames) %>% 
  hmSideColors(axis = 'y', side.colors = rsc,
    palette = rsccols, names = rscnames)
    

About

A D3.js-based heatmap htmlwidget for R

License:Other


Languages

Language:HTML 47.5%Language:R 45.7%Language:JavaScript 4.4%Language:CSS 2.5%