作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我用library(ComplexHeatmap)
制作了这个图
我希望 Z-score
位于底部位置,而类别变量显示在右侧。 This post接近了,但我无法像下面的脚本那样使用 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)]))
并使用这个脚本
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 = c("Ctrl" = "#D1B551", "Tumor" = "#678F53"),
Type = c("Ctrl" = "#D1B551", "Cell_type1" = "green", "Cell_type2" = "blue")),
annotation_legend_param = list(
Case = list(
title_gp = gpar(fontsize = 16,
fontface = "bold"),
labels_gp = gpar(fontsize = 16)),
Type = list(
title_gp = gpar(fontsize = 16,
fontface = "bold"),
labels_gp = gpar(fontsize = 16)))),
heatmap_legend_param = list(
legend_direction = "horizontal",
legend_width = unit(6, "cm")),
),
heatmap_legend_side = "bottom"
)
最佳答案
尝试使用draw
命令的选项legend_grouping = "original"
。
library(ComplexHeatmap)
library(circlize)
set.seed(123)
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)]))
And using this script
df <- data.frame(Case = hmap[, c(13:14)]$malig,
Type = hmap[, c(13:14)]$type)
annot <- rowAnnotation(
df = data.frame(Case = hmap[, c(13:14)]$malig,
Type = hmap[, c(13:14)]$type),
col = list(Case = c("Ctrl" = "#D1B551", "Tumor" = "#678F53"),
Type = c("Ctrl" = "#D1B551", "Cell_type1" = "green",
"Cell_type2" = "blue")),
annotation_legend_param = list(
Case = list(
title_gp = gpar(fontsize = 16,
fontface = "bold"),
labels_gp = gpar(fontsize = 16)),
Type = list(
title_gp = gpar(fontsize = 16,
fontface = "bold"),
labels_gp = gpar(fontsize = 16)))
)
htmp <- 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 = annot,
heatmap_legend_param = list(
legend_direction = "horizontal",
legend_width = unit(6, "cm")),
)
draw(htmp, heatmap_legend_side="bottom", annotation_legend_side="right",
legend_grouping = "original")
关于r - ComplexHeatmap:如何以不同方式放置热图图例和注释图例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68483646/
我用library(ComplexHeatmap)制作了这个图 我希望 Z-score 位于底部位置,而类别变量显示在右侧。 This post接近了,但我无法像下面的脚本那样使用 rowAnnota
您好,我正在使用 ComplexHeatmap 包并遵循了他们的小插图,但是出于某种原因,我似乎无法强制图例变为水平。所以例如这里是一个例子, set.seed(123) library(Comple
您好,我正在使用 ComplexHeatmap 包并遵循了他们的小插图,但是出于某种原因,我似乎无法强制图例变为水平。所以例如这里是一个例子, set.seed(123) library(Comple
我是一名优秀的程序员,十分优秀!