简体   繁体   中英

How to bold a group of labels or branches in heatmap.2 in R

By using the data from heatmap.2:

data(mtcars)    
x<-scale(mtcars)
set.seed(123)
tf<-sample(rownames(x), 5)
tf

[1] "Merc 280"         "Pontiac Firebird" "Merc 450SL"  
 "Fiat X1-9"        "Porsche 914-2" 

heatmap.2(x)

I wanted put in bold row names in tf (on the right). I dug around and I can't find the solutions, only for a color names. Does anybody have suggestions using the above sample?

We can try this function written by @skafdasschaf :

make_bold_names <- function(mat, rc_fun, rc_names) {
  bold_names <- rc_fun(mat)
  ids <- rc_names %>% match(rc_fun(mat))
  ids %>%
    walk(
      function(i)
        bold_names[i] <<-
        bquote(bold(.(rc_fun(mat)[i]))) %>%
        as.expression()
    )
  bold_names
}

Then:

library(gplots)
library(dplyr)
library(purrr)

data(mtcars)    
x<-scale(mtcars)
set.seed(123)
tf<-sample(rownames(x), 5)
hm = heatmap.2(x)

heatmap.2(x,labRow=make_bold_names(x,rownames,tf),margins=c(8,8))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM