##热图展示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
)
单细胞marker基因展示之热图
最新推荐文章于 2024-05-23 00:00:00 发布