【发布时间】:2021-09-14 13:35:40
【问题描述】:
我发现了一个有趣的函数,可以用粗体标记热图的一些行名。 我已经对其进行了调整,使其以斜体形式执行相同的操作,并且我想知道如何才能更多地调整此代码,以便将某些行名以粗体显示,而将其他行名以斜体显示。请找到这两个函数和热图(我正在使用找到的相同示例来解释该函数)。
library(pheatmap)
library(tidyverse)
# Create test matrix
test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")
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
}
make_italic_names <- function(mat, rc_fun, rc_names) {
italic_names <- rc_fun(mat)
ids <- rc_names %>% match(rc_fun(mat))
ids %>%
walk(
function(i)
italic_names[i] <<-
bquote(italic(.(rc_fun(mat)[i]))) %>%
as.expression()
)
italic_names
}
pheatmap(
test,
labels_row = make_bold_names(test, rownames, c("Gene2", "Gene5", "Gene14")))
使用两个labels_row显然是行不通的
pheatmap(
test,
labels_row = make_bold_names(test, rownames, c("Gene2", "Gene5", "Gene14")),
labels_row = make_italic_names(test, rownames, c("Gene3", "Gene6", "Gene10")))
【问题讨论】: