Multiple RowSideColor columns heatmap.2 from gplots package

Brad Davis picture Brad Davis · Sep 3, 2014 · Viewed 8k times · Source

I would like to be able to have use two RowSideColor bars with the heatmap.2 function from the R package plots, but I can't figure out how to do it. I've seen this question asked before on stack overflow, and while the question was responded to, the responses didn't address the question. Adding the factors to the input data matrix won't work because it would affect the results of the hierarchical clustering. I am open to using other heatmap-like functions to achieve my goals if that's necessary.

Thanks, Brad

Answer

ping picture ping · Sep 3, 2014

I've wanted to do this before and always used to make two heatmaps and copy and paste one RowSideColors bar from one heatmap onto the other one. I just did some more searching and found the heatmap.plus package that can do this, though:

# install.packages("heatmap.plus") #install package
require("heatmap.plus")

data(cars) # using cars data as example

# create a matrix of colors for RowSideColors
myCols = cbind(rep(c("yellow", "blue"), 25), rep(c("red", "green"), 25))

heatmap.plus(data.matrix(cars), RowSideColors=myCols)

The RowSideColors argument in this package can accept a matrix of colors to plot multiple row side colors.