0

So instead of using the rownames from my matrix as the row labels, I want to use a different set of non-unique labels. (The nuance here is that I can't set these labels as the rownames in the matrix, since they aren't unique. - I'm hoping that using the labRow option will allow me to circumvent that.)

labRow = df1$type where df1$name matches rowname of x

I think it might require something a little more complicated, like found here: Make row labels italic in heatmap.2

DF1

             name        type
1            Mazda RX4   A
2        Mazda RX4 Wag   A
3           Datsun 710   B
4       Hornet 4 Drive   B
5    Hornet Sportabout   B
6              Valiant   C
7           Duster 360   A
8            Merc 240D   B
9             Merc 230   C
10            Merc 280   C

Heatmap:

data(mtcars)
 x  <- as.matrix(mtcars)
heatmap.2(x)

Not sure how to accomplish this within heatmpa.2. Wondering if it would be by using merge? Or something else?

Desired output would be a heatmap with the row labels being they type instead of car name.

Steve
  • 588
  • 4
  • 17

1 Answers1

0

It looks like this does the trick. I even mixed up the column order to see if it would work with the dendrograms

data(mtcars)
x  <- as.matrix(mtcars)
heatmap.2(x)

df1 <- as.data.frame(row.names(mtcars))
df1$type <- c("a","b","c","a","b","c","a","b","c","a","b","c","a","b","c","a","b","c","a","b","c","a","b","c","a","b","c","a","b","c","a","b")

df1 <- df1[order(df1$type),]

labRow <- df1$type[match(row.names(x), df1$'row.names(mtcars)') ]

heatmap.2(x, labRow = labRow)
Steve
  • 588
  • 4
  • 17