4

I'm trying to make my row labels italic using the R function heatmap.2. There's no default option and I can't figure out a work around by setting par(font=3) for example. How can I set my row labels to be italic in heatmap.2?

set.seed(123)
data = matrix(sample(100), nrow=10, ncol=10)
rownames(data) = c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J")

library(gplots)

heatmap.2(data,
           Colv=TRUE,
           Rowv=TRUE,
           xlab=NA,
           ylab=NA)
eipi10
  • 91,525
  • 24
  • 209
  • 285
Erik
  • 123
  • 2
  • 7
  • `expression(italic())` works here. Just need to figure out a way to sneak it into `heatmap.2` function. – M-- Jul 25 '19 at 18:44
  • Unfortunately, that only results in a row labeled: italic("B"). Any suggestions on how to approach sneaking it into heatmap.2? – Erik Jul 25 '19 at 23:08
  • Run `heatmap2` without any arguments. The source code will apear. You need to change the `axis(...)` function. – M-- Jul 25 '19 at 23:12

1 Answers1

4

You can use the labCol and labRow arguments to heatmap.2 to pass in the labels. We just need to figure out how to pass these in as a list of plotmath expressions. I always find this painful, as I don't do it often enough to remember the appropriate incantations, but was able to put the code together by adapting this R-help answer. Note that the matrix needs to have column names, which I've added in the code below

library(gplots)

# Fake data
set.seed(123)
data = matrix(sample(100), nrow=10, ncol=10)
rownames(data) = c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J")
colnames(data) = 1:ncol(data)

heatmap.2(data,
          Colv=TRUE,
          Rowv=TRUE,
          labCol=as.expression(lapply(colnames(data), function(a) bquote(italic(.(a))))),
          labRow=as.expression(lapply(rownames(data), function(a) bquote(italic(.(a))))),
          xlab=NA,
          ylab=NA)

enter image description here

eipi10
  • 91,525
  • 24
  • 209
  • 285