使用pheatmap在r中重塑热图的问题
problem reshaping heatmap in r using pheatmap
有谁知道如何重塑我的热图,使其与我发布的第二个热图相似?我需要基本上切换所有方面。
我尝试了几个解决方案,但似乎没有任何效果。我正在使用 pheatmap()
.
这是我的代码:
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"
)
应该这样排序,如果有人知道如何切换我的热图以匹配第二个热图,我将不胜感激。
您可以使用 t()
转置您的输入矩阵。然后,您必须相应地更改依赖于热图 rows/columns 的其他参数:
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"
)
有谁知道如何重塑我的热图,使其与我发布的第二个热图相似?我需要基本上切换所有方面。
我尝试了几个解决方案,但似乎没有任何效果。我正在使用 pheatmap()
.
这是我的代码:
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"
)
应该这样排序,如果有人知道如何切换我的热图以匹配第二个热图,我将不胜感激。
您可以使用 t()
转置您的输入矩阵。然后,您必须相应地更改依赖于热图 rows/columns 的其他参数:
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"
)