【问题标题】:Change colors in multiple annotations更改多个注释中的颜色
【发布时间】:2023-03-21 15:46:01
【问题描述】:

我想更改热图多个注释的颜色。示例代码:

#test data
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 = "")
#plot
annotation <- data.frame(Var1 = factor(1:10 %% 2 == 0, labels = c("Exp1", "None")), Var1 = factor(1:10 %% 2 == 0, labels = c("Exp1", "None")))
rownames(annotation) <- colnames(test) # check out the row names of annotation
pheatmap(test, annotation = annotation)

预期结果是None 类别中的白色和Exp1Exp2 类别中的黑色。

【问题讨论】:

    标签: r pheatmap


    【解决方案1】:

    指定annotation_colors

    # Specify colors
    annotation_colors = list(
      Var1 = c(Exp1="black", None="white"),
      Var1.1 = c(Exp1="black", None="white"))
    pheatmap(test, annotation = annotation, annotation_colors = annotation_colors)
    

    【讨论】:

    • 完美运行。谢谢!
    猜你喜欢
    • 2011-10-22
    • 2021-12-27
    • 2011-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-29
    • 1970-01-01
    相关资源
    最近更新 更多