單細(xì)胞繪圖系列:
- Seurat繪圖函數(shù)總結(jié)
- 使用ggplot2優(yōu)化Seurat繪圖
- scRNAseq靈活的點(diǎn)圖繪制:FlexDotPlot
- 富集分析結(jié)果雷達(dá)圖
1. 使用DoHeatmap
繪制Seurat自帶熱圖
library(Seurat)
library(dplyr)
pbmc <- readRDS("pbmc.rds") #導(dǎo)入注釋好的演示數(shù)據(jù)集
pbmc.markers <- FindAllMarkers(pbmc,only.pos = T,min.pct = 0.1,logfc.threshold = 0.25)
top10 <- pbmc.markers%>%group_by(cluster)%>%top_n(n=10,wt=avg_log2FC)
DoHeatmap(pbmc,features = top10$gene)+NoLegend()
##DoHeatmap輸入的的是scale.data矩陣
稍作優(yōu)化(調(diào)整熱圖顏色+調(diào)整細(xì)胞類型標(biāo)簽顏色惧浴,最好與UMAP圖一致)
DoHeatmap(pbmc,
features = as.character(unique(top10$gene)),
group.by = "cell_type",
assay = "RNA",
group.colors = c("#C77CFF","#7CAE00","#00BFC4","#F8766D","#AB82FF","#90EE90","#00CD00","#008B8B"))+ #設(shè)置組別顏色
scale_fill_gradientn(colors = c("navy","white","firebrick3"))
scale_fill_gradientn()系列函數(shù)用法見:ggplot2點(diǎn)圖
更改橫軸順序(根據(jù)實際需要)
pbmc$cell_type <- factor(x = pbmc$cell_type, levels = c('Naive CD4 T','Memory CD4 T','CD8 T','CD14+ Mono','FCGR3A+ Mono','B','NK','DC','Platelet'))
DoHeatmap(pbmc,
features = as.character(unique(top10$gene)),
group.by = "cell_type",
assay = "RNA",
group.colors = c("#C77CFF","#7CAE00","#00BFC4","#F8766D","#AB82FF","#90EE90","#00CD00","#008B8B","#FFA500"))+ #設(shè)置組別顏色
scale_fill_gradientn(colors = c("navy","white","firebrick3"))#設(shè)置熱圖顏色
2. 使用ComplexHeatmap
繪制帶特定基因的熱圖
ComplexHeatmap
優(yōu)點(diǎn):功能非常強(qiáng)大,支持一張熱圖中分組分別聚類(control之間聚類嗦董,treatment之間聚類)
缺點(diǎn):參數(shù)基本上只適用于這一個包
參考:https://jokergoo.github.io/ComplexHeatmap-reference/book/
library(ComplexHeatmap)
##提取標(biāo)準(zhǔn)化表達(dá)矩陣
#??提取scale.data矩陣的時候一定要注意妓湘,做ScaleData()的時候一定是scale了所有的基因普气,而不是默認(rèn)的2000個基因
mat <- GetAssayData(pbmc,slot = 'scale.data')
##獲得基因和細(xì)胞聚類信息
gene_features <- top10
cluster_info <- sort(pbmc$cell_type)
##篩選矩陣
mat <- as.matrix(mat[top10$gene,names(cluster_info)])
##輸入想在圖上展示出來的marker基因泡嘴,獲得基因在熱圖中的位置信息
gene <- c('CD3E','CD8B','S100A9','CD14','LYZ',"CD79B","GNLY","GZMB","PF4")
gene_pos <- which(rownames(mat)%in%gene)
row_anno <- rowAnnotation(gene=anno_mark(at=gene_pos,labels = gene))
##畫個熱圖看看
Heatmap(mat,
cluster_rows = FALSE,
cluster_columns = FALSE,
show_column_names = FALSE,
show_row_names = FALSE,
column_split = cluster_info,
right_annotation = row_anno)
做一下美化,調(diào)整一下顏色
##設(shè)置列標(biāo)簽的顏色鸣个,最好和umap/tsne細(xì)胞群的顏色一一對應(yīng)
col <- c('plum','coral1','bisque','gold2','hotpink3','lightsalmon3','rosybrown2','lightcyan2','thistle3')
names(col) <- levels(cluster_info)
top_anno <- HeatmapAnnotation(cluster=anno_block(gp=gpar(fill=col),
labels = levels(cluster_info),
labels_gp = gpar(cex=0.5,col='white')))
##給熱圖改個好看的顏色
library(circlize)
col_fun = colorRamp2(c(-2, 1, 4), c("#377EB8", "white", "#E41A1C"))
#col_fun2 = colorRamp2(c(-2, 1, 4), c("#92b7d1", "white", "#d71e22"))
Heatmap(mat,
cluster_rows = FALSE,
cluster_columns = FALSE,
show_column_names = FALSE,
show_row_names = FALSE,
column_split = cluster_info,
top_annotation = top_anno, #在熱圖邊上增加注釋
column_title = NULL,
right_annotation = row_anno,
heatmap_legend_param = list(
title='Expression',
title_position='leftcenter-rot'),
col = col_fun)
完成~