2

As indicated in the title above, I want to change the column labels in the heatmap figure produced by heatmap.2 from package gplots in R to symbols rather than text. May I know if it is possible, and if so, how to do it?

This is a sample code to generate heatmap using heatmap.2:

library(gplots)
data<-sample(1:100,size=80)
M<-matrix(data,nrow=10,ncol=8)
colnames(M)<-c("W1_1","W1_2","W1_3","W1_4","B1_1","B1_2","B1_3","B1_4")
heatmap.2(M, trace="none", dendrogram="none")

This is the heatmap result:

enter image description here

In this case, the column labels are "W1_1","W1_2","W1_3","W1_4","B1_1","B1_2","B1_3","B1_4". May I know If it is possible to use two symbols to represent W1 and B1 group respectively and show in the final figure.

I have attached a sample below (changed via photoshop):

enter image description here

Thanks in advance for all the helps!

mt1022
  • 16,834
  • 5
  • 48
  • 71
fyr91
  • 1,253
  • 5
  • 17
  • 33
  • You should really specify what package `heatmap.2` is from, and I'm not sure why you tagged it [tag:ggplot2] if you're not using it. – alistaire Jan 16 '17 at 04:17
  • Dear alistaire @alistaire, I thought there might be a solution with ggplot2 :). The heatmap.2 package is from gplots. – fyr91 Jan 16 '17 at 04:19

1 Answers1

0

Here's another possibility with standard image function:

op <- par(mar=c(4,2,2,4))
image(seq(nrow(M)), seq(ncol(M)), M, axes=F, xlab="", ylab="")
axis(side=4, at=seq(ncol(M)))
par(xpd=TRUE)
points(seq(nrow(M)), rep(0, nrow(M)), 
  pch=c(16, 15), col=c("cyan", "pink"), cex=2
)
par(op)

enter image description here

Marc in the box
  • 11,769
  • 4
  • 47
  • 97