top_marker_genes热图可视化

单细胞数据处理中,如何将第一张图变成第二张图
P1


image.png

P2


image.png
#---------单细胞教程step7

#1.1 得到top_marker_genes的相关信息,为data.frame
library(dplyr) 
top5 <- sce.markers %>% group_by(cluster) %>% top_n(5, avg_log2FC)
DoHeatmap(sce ,top3$gene,size=3)
#1.2 对数据进行标准化
sce.all <- ScaleData(sce,features =  top5$gene)  

#2.1 将基因按群体分割并排序
ll = split(top5$gene,top5$cluster)
ll = ll[ord]

#2.2 去除在多个群体中重复出现的基因
rmg=names(table(unlist(ll))[table(unlist(ll))>1])
ll = lapply(ll, function(x) x[!x %in% rmg])

#3.1 定义颜色

library(paletteer) 
color <- c(paletteer_d("awtools::bpalette"),
           paletteer_d("awtools::a_palette"),
           paletteer_d("awtools::mpalette"))
myc = c('#d73027','#f46d43','#fdae61','#fee090',
        '#ffffbf','#e0f3f8','#abd9e9','#74add1','#4575b4')

#3.2 将细胞类型转换为因子变量并设定顺序
#------绘制热图时更有序及易于解读
unique(sce.all$celltype)
ord = c('Naive CD4 T' ,'Memory CD4 T', 'CD8 T', 'NK', 
        'CD14+ Mono', 'FCGR3A+ Mono' ,'DC',  'B','Platelet')
sce.all$celltype = factor(sce.all$celltype ,levels = ord)

#4. 可视化
library(ggplot2)
DoHeatmap(sce.all,
          features = unlist(ll),
          group.by = "celltype",
          assay = 'RNA',
          group.colors = myc,label = F)+
  scale_fill_gradientn(colors = c("white","grey","firebrick3"))

>引自生信技能树
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容