单细胞marker基因展示之热图

##热图展示marker基因
1.seurat自带
scRNA1 <-  ScaleData(scRNA1,features = rownames(scRNA1))
cells = subset(scRNA1,downsample=300)##取其中的300个细胞,为了图好看
top10 <- marker %>% 
  #  filter(cluster!="other") %>%
  group_by(cluster) %>% 
  top_n(10, avg_log2FC) 

DoHeatmap(cells,features = top10$gene,size = 3,
  label = F,slot = "scale.data")+scale_fill_gradientn(colors = c("#4DBBD5","white","#E64B35"))
?DoHeatmap
ggsave(filename=paste0(pro,'DoHeatmap_check_top3_markers_by_clusters-2.pdf') ,
       width=10,height=8)

#用pheatmap画
library(pheatmap)
colanno=cells@meta.data 
colanno$celltype=factor(colanno$celltype,levels = unique(colanno$celltype))
colanno1=colanno[,6]
colanno1=as.data.frame(colanno1)
rownames(colanno1)=rownames(colanno)
colnames(colanno1)="celltype"
##先对细胞进行排序,按照celltype的顺序,然后对基因排序
rowanno=top10
colnames(top10)
rowanno=rowanno%>%arrange(cluster)
##提取scale矩阵的行列时,按照上面的顺序
mat4=cells[["RNA"]]@scale.data[rowanno$gene,rownames(colanno1)]
mat4[mat4>=2.5]=2.5
mat4[mat4 < (-1.5)]= -1 #小于负数时,加括号!

pheatmap(mat4,cluster_rows = F,cluster_cols = F,
         show_colnames = F,
         scale= "row",
         annotation_col = colanno1,
         gaps_row=as.numeric(cumsum(table(rowanno$cluster))[-6]),
         gaps_col=as.numeric(cumsum(table(colanno$celltype))[-6]) 
         
)
##cumsum(x) :返回 x 向量的累计和
?pheatmap
##保存为pdf
pheatmap(mat4,cluster_rows = F,cluster_cols = F,
         show_colnames = F,
         annotation_col = colanno1,
         gaps_row=as.numeric(cumsum(table(rowanno$cluster))[-6]),
         gaps_col=as.numeric(cumsum(table(colanno$celltype))[-6]) ,
         filename="marker.heatmap.pdf",width=11,height = 7
)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值