在回答了这个问题之后,我发现了pheatmap函数(与heatmap.2相比,它可以为我提供更多的控制权)。
我有两个问题:
1-我无法更改注释(类别)的颜色
2-即使我将输出保存在png文件中,图形窗口也会不断弹出
这是我的MWE:
library(pheatmap)
library(RColorBrewer)
cols <- colorRampPalette(brewer.pal(9, "Set1"))
mymat <- matrix(rexp(600, rate=.1), ncol=12)
colnames(mymat) <- c(rep("treatment_1", 3), rep("treatment_2", 3), rep("treatment_3", 3), rep("treatment_4", 3))
rownames(mymat) <- paste("gene", 1:dim(mymat)[1], sep="_")
annotdf <- data.frame(row.names = paste("gene", 1:dim(mymat)[1], sep="_"), category = c(rep("CATEGORY_1", 10), rep("CATEGORY_2", 10), rep("CATEGORY_3", 10), rep("CATEGORY_4", 10), rep("CATEGORY_5", 10)))
mycolors <- cols(length(unique(annotdf$category)))
names(mycolors) <- unique(annotdf$category)
mycolors <- list(mycolors = mycolors)
pheatmap(mymat,
color=greenred(75),
scale="row",
cluster_rows = FALSE,
cluster_cols = FALSE,
gaps_row=c(10,20,30,40),
gaps_col=c(3,6,9),
cellheight = 6,
cellwidth …Run Code Online (Sandbox Code Playgroud) 我有以下数据:
dat <- structure(list(GO = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 4L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("apoptotic process",
"metabolic process", "negative regulation of apoptotic process",
"positive regulation of apoptotic process", "signal transduction"
), class = "factor"), ProbeGene = structure(c(14L, 15L, 2L, 12L,
7L, 11L, 16L, 8L, 19L, 13L, 3L, 1L, 18L, 4L, 10L, 5L, 9L, 17L,
20L, 6L), .Label = c("1416787_at Acvr1", "1418835_at Phlda1",
"1419282_at Ccl12", "1423240_at Src", "1424896_at …Run Code Online (Sandbox Code Playgroud) 我知道如何使用 pheatmap 按注释类别对行(基因)进行分组,并且我知道如何对整个行(基因)集执行 Person 的相关聚类,但我想要完成的是执行聚类(并显示独立的树状图)独立于每个类别。
这甚至可能吗?或者我是否被迫为每个类别创建单独的热图以在类别的基础上进行聚类?
在下面检查我的 MWE:
set.seed(1)
library(pheatmap)
mymat <- matrix(rexp(600, rate=.1), ncol=12)
colnames(mymat) <- c(rep("treatment_1", 3), rep("treatment_2", 3), rep("treatment_3", 3), rep("treatment_4", 3))
rownames(mymat) <- paste("gene", 1:dim(mymat)[1], sep="_")
annotdf <- data.frame(row.names = paste("gene", 1:dim(mymat)[1], sep="_"), category = c(rep("CATEGORY_1", 10), rep("CATEGORY_2", 10), rep("CATEGORY_3", 10), rep("CATEGORY_4", 10), rep("CATEGORY_5", 10)))
pheatmap(mymat,
scale="row",
cluster_rows = FALSE,
cluster_cols = FALSE,
gaps_row=c(10,20,30,40),
gaps_col=c(3,6,9),
cellheight = 6,
cellwidth = 20,
border_color=NA,
fontsize_row = 6,
filename = "TEST1.png",
annotation_row = annotdf
)
pheatmap(mymat,
scale="row",
cluster_rows = …Run Code Online (Sandbox Code Playgroud)