使用Pheatmap

问题描述

有人知道如何重塑我的热图,使其类似于我发布的第二个热图吗?我基本上需要切换所有方面。 我尝试了几种解决方案,但似乎没有任何效果。我正在使用pheatmap()

enter image description here

这是我的代码:

library(pheatmap)
library(grid)

all_data2 <- cbind(amino,sphingo,hexoses,phospha,lyso,acyl)
matrix_data <- as.matrix(amino[,3:31])
rownames(matrix_data) <- sample_id$`Sample Identification`
heatmap_final <- matrix_data[,!colnames(matrix_data) %in% c('Sample Identification.1','Sample Identification.2','Sample Identification','Time point.1','Time point.2','Time point')]

all_data2 = data.frame("Time point" = c(rep("T0",45),rep("T1",45)))
rownames(all_data2) = rownames(heatmap_final) # name matching

heatmap_final[order(rownames(heatmap_final)),order(colnames(heatmap_final))]

draw_colnames_45 <- function (coln,gaps,...) {
 coord <- pheatmap:::find_coordinates(length(coln),gaps)
 x     <- coord$coord - 0.5 * coord$size
 res   <- grid::textGrob(
   coln,x = x,y = unit(1,"npc") - unit(3,"bigpts"),vjust = 0.75,hjust = 1,rot = 45,gp = grid::gpar(...)
 )
 return(res)
}
assignInNamespace(
 x = "draw_colnames",value = "draw_colnames_45",ns = asNamespace("pheatmap")
)


 
 
pheatmap(
 mat = log2(heatmap_final),scale = "column",annotation_row = all_data2,cluster_rows = F,show_rownames = TRUE,drop_levels = TRUE,fontsize = 5,clustering_method = "complete",main = "Hierachical Cluster Analysis"
)



应该这样排序,如果有人对如何切换我的热图来匹配第二个热图有想法,我将不胜感激。

enter image description here

解决方法

您可以使用t()转置输入矩阵。然后,您必须相应地更改取决于热图的行/列的其他参数:

pheatmap(
 mat = t(log2(heatmap_final)),scale = "row",annotation_col = all_data2,cluster_cols = F,show_rownames = TRUE,drop_levels = TRUE,fontsize = 5,clustering_method = "complete",main = "Hierachical Cluster Analysis"
)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...