【问题标题】:Changing the legend in complex heatmap更改复杂热图中的图例
【发布时间】:2021-01-10 19:38:52
【问题描述】:

有了这段代码,我就有了这个复杂的热图

library(dplyr)
library(rafalib)
library(RColorBrewer)
#if (!requireNamespace("BiocManager", quietly = TRUE))
#  install.packages("BiocManager")
#BiocManager::install("genefilter")
library(genefilter)
library(gplots)
library(ComplexHeatmap)
library(circlize)
library(scales)
library(stringr)
library(reshape2)
library(Seurat)
library(limma)
library(dropbead)
library(sctransform)
library(Matrix)
library(ggrepel)
library(viridis)
library(tidyverse)
library(cowplot)


left_annotation = rowAnnotation(Peak = anno_text(left_anno$Peak),
                                Percentage = anno_barplot(left_anno$Percentage_altered_nr,
                                                          gp = gpar(fill = "gold"),
                                                          axis_param = list(direction = "reverse"),
                                                          width = unit(20, "mm"),ylim = c(0, 70))

right_annotation = rowAnnotation(Percentage = anno_barplot(right_anno$Percentage_altered_r,
                                                          gp = gpar(fill = "gold"),
                                                          width = unit(20, "mm"),ylim = c(0, 60)
                                                          ))

Heatmap(mat, border = T, show_column_names = F,
        rect_gp = gpar(col = "white", lwd = 1),
        column_split = response$response, 
        col = col_fun,
        show_column_dend = F,
        show_row_dend = F,
        left_annotation = left_annotation,
        right_annotation = right_annotation,name = "CNV")

[![在此处输入图片描述][1]][1]

这是我的 R 对象

1- 问题是,在块中颜色是离散的,但在图例中您看到的是 1 0 -1 -2 。我怎样才能改变传说中的所以我有red作为Ampblue作为Delgrey作为Netral好吗?

2- 我怎样才能使基因变为斜体

【问题讨论】:

  • 你能让你的问题重现吗?包括包和数据,以便人们可以运行您的代码。谢谢。
  • 谢谢你把我的全部数据贴在这里
  • 您需要所有数据和所有这些软件包来重现问题吗?似乎您处理的是一个连续的图例,但想要一个使用 ggplot2 的离散图例?!这可能会有所帮助R ggplot2: legend should be discrete and not continuous

标签: r heatmap


【解决方案1】:
Heatmap(mat, border = T, show_column_names = F,
        rect_gp = gpar(col = "white", lwd = 1),
        column_split = response$response, 
        col = c("-2" = "blue", "0" = "grey", "1" = "red"),
        heatmap_legend_param = list(at = c("-2", "0", "1"), labels = c("Del", "Netral", "Amp")),
        show_column_dend = F,
        show_row_dend = F,
        left_annotation = left_annotation,
        right_annotation = right_annotation,name = "CNV",
        row_names_gp = gpar("fontface" = "italic")
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-19
    • 2017-01-16
    • 2013-06-28
    • 2021-10-26
    • 2021-11-25
    • 1970-01-01
    相关资源
    最近更新 更多