我制作了这个情节library(ComplexHeatmap)
我希望Z-score位于底部位置,而分类变量显示在右侧。这篇文章rowAnnotation很接近,但我无法像下面的脚本一样使用它。
预期产出
有了这些数据:
set.seed(123)
library(ComplexHeatmap)
mat = matrix(rnorm(96, 2), 8, 12)
mat = rbind(mat, matrix(rnorm(48, -2), 4, 12))
hmap <- as.data.frame(t(mat))
hmap$type <- rep(c("Ctrl", "Cell_type1", "Cell_type2"), 4)
hmap$malig <- ifelse(hmap$type == "Ctrl", "Ctrl", "Tumor")
hmap_bt <- scale(as.matrix(hmap[, -c(13:14)]))
Run Code Online (Sandbox Code Playgroud)
并使用这个脚本
draw(Heatmap(hmap_bt,
name = "Z-score",
col = colorRamp2(c(-2, 0, 2), c("#6DBCC3", "white", "#8B3A62")),
show_column_names = FALSE,
show_column_dend = FALSE,
column_km = 3,
left_annotation = rowAnnotation(Case = hmap[, c(13:14)]$malig,
Type = hmap[, c(13:14)]$type,
col = list(Case …Run Code Online (Sandbox Code Playgroud) 我使用 R 中的复杂热图库根据我的数据制作了热图。下面是我使用的代码以及示例数据。
数据
Gene T1 T2 T3 T4
ARL2-SNX15 4.678845561 3.728158677 4.825892144 3.189954084
PALM 2.657130448 2.880786566 3.054500641 2.408040399
AC239800.3 4.190678312 4.226734964 2.701671155 4.745703221
HBG2 12.09275318 11.943057 12.54390598 11.97291386
ALDH3B2 1.599244728 1.533113992 0.97241763 1.595816246
IGKV1-39 4.67511509 5.139282438 4.79232686 4.853376044
RNU1-2 2.833601135 2.565489873 1.982653588 2.590228834
RNU1-27P 3.006656094 2.851094423 2.135404861 3.214987282
RPL9 9.716225455 9.438792748 9.843155568 9.620418751
HBB 15.00426572 14.86490879 14.9677195 14.97970035
RAP1GAP 5.886838373 5.792277665 7.195829067 5.255034813
HBA1 14.62993733 14.40249302 14.89753465 14.48068449
TUBB1 10.27923383 10.01917144 10.34000216 10.24278332
RNF182 3.44912724 3.949744939 3.511681562 3.971171624
RPL13AP5 …Run Code Online (Sandbox Code Playgroud) 您好,我正在使用 ComplexHeatmap 包并遵循他们的小插图,但由于某种原因,我似乎无法强制图例变为水平。例如,这里是一个例子,
set.seed(123)
library(ComplexHeatmap)
mat = matrix(rnorm(80, 2), 8, 10)
mat = rbind(mat, matrix(rnorm(40, -2), 4, 10))
rownames(mat) = paste0("R", 1:12)
colnames(mat) = paste0("C", 1:10)
ha_column = HeatmapAnnotation(df = data.frame(type1 = c(rep("a", 5), rep("b", 5))),
col = list(type1 = c("a" = "red", "b" = "blue")),
annotation_legend_param = list(type1 = list(
title_gp = gpar(fontsize = 16),
legend_direction = "horizontal", labels_gp = gpar(fontsize = 8)))
)
ht1 = Heatmap(mat, name = "ht1", column_title = "Heatmap 1", top_annotation = ha_column)
draw(ht1, heatmap_legend_side …Run Code Online (Sandbox Code Playgroud)