gpt4 book ai didi

r - 如何更改 pheatmap 中的注释颜色?

转载 作者:行者123 更新时间:2023-12-04 14:46:17 92 4
gpt4 key购买 nike

考虑矩阵:

test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")

#creating group to divide

group_df = data.frame(Groups=rep(c("Control", "Treated"), c(5,5)))
rownames(group_df) <- colnames(test)

#生成热图:

pheatmap(test, cluster_cols = FALSE, scale = 'row',
annotation_col = group_df,
show_colnames = FALSE,
border_color = "white",
colorRampPalette(c("#00FF00", "white", "#DC143C"))(75),
gaps_col = cumsum(c(5,5)))

如何将 ControlTreated 的颜色从蓝色和红色更改为不同的颜色?

heatmap

最佳答案

group_df 更改为一个因子并指定 annotation_colors 将起作用。

group_df = data.frame(Groups=as.factor(rep(c("Control", "Treated"), c(5,5))))

ann_colors = list(
Groups = c(Control="black", Treated="white"))

rownames(group_df) <- colnames(dummy)
pheatmap(dummy, cluster_cols = FALSE, scale = 'row',
annotation_col = group_df,
annotation_colors = ann_colors,
show_colnames = FALSE,
border_color = "white",
colorRampPalette(c("#00FF00", "white", "#DC143C"))(75),
gaps_col = cumsum(c(5,5)))

enter image description here

关于r - 如何更改 pheatmap 中的注释颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69984316/

92 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com