偷偷问一下,关注了吗?
内容获取
1、购买打包合集(2025KS微信VIP付费合集),价格感人,可以加入微信VIP群(答疑交流群,甚至有小伙伴觉得群比代码更好),可以获取建号以来所有内容,群成员专享视频教程,提前更新,其他更多福利!
2、《KS科研分享与服务》公众号有QQ群,进入门槛是20元(完全是为了防止白嫖党,请理解),请考虑清楚。群里有免费推文的注释代码和示例数据(终身拥有),没有付费内容,群成员福利是购买单个付费内容半价!
需要者详情请联系作者(非需要者勿扰,处理太费时间):
我们很久之前介绍过一个R包-Scillus(单细胞番外---单细胞数据分析R包Scillus之marker基因可视化(中)),介绍她的原因也说了,无他,完全是一些可视化很好,例如这个热图,可以做到多层注释,很多小伙伴也在高分文章中看到这个图,但是使用Scillus做这个热图很容易出问题。所以这里我们参考之前对DotHeatmap改造的帖子(单细胞基因可视化之热图的根本改造2),以此为基础,写一个函数,做出好的可视化:
效果如下:
函数使用解说见B站:
https://www.bilibili.com/video/BV1rkcUeaENo/?spm_id_from=333.1387.homepage.video_card.click&vd_source=05b5479545ba945a8f5d7b2e7160ea34
热图的特点是可做多层注释,无论是分组还是连续数值,可自定义颜色,具体参数如下,当然了,如果还想继续修饰,可以做更多的参数,我们这里提供框架,自行修改即可,按照实际需求:
marker基因可以自定义,这里我们Findmarker做的,用来演示:
#### My Heatmap
library(Seurat)
library(ComplexHeatmap)
library(dplyr)
library(circlize)
markers <- FindAllMarkers(human_data,logfc.threshold = 0.25,min.pct = 0.25,only.pos = T)
markers_plot1 <- markers %>% filter(p_val_adj < 0.05) %>% group_by(cluster) %>% top_n(n=10, wt=avg_log2FC)
markers_plot <- unique(markers_plot1$gene)
单层注释:
ks_single_marker_heatmap(object=human_data,assay = 'RNA',genes = markers_plot, bar = c("celltype"))
调整celltype顺序:
#调整celltype顺序
#基因排序
markers_plot1$cluster <- factor(markers_plot1$cluster, levels = unique(human_data$celltype))
markers_plot1 <- markers_plot1[order(markers_plot1$cluster), ,drop=F]
ks_single_marker_heatmap(object=human_data,assay = 'RNA',
genes = markers_plot1$gene, bar = c("celltype"),
cluster_order = unique(human_data$celltype))
#如果想要基因排序是反的,rev一下基因基因
ks_single_marker_heatmap(object=human_data,assay = 'RNA',
genes = rev(markers_plot1$gene), bar = c("celltype"),
cluster_order = unique(human_data$celltype))
多层注释,自定义颜色:
#多层注释
ks_single_marker_heatmap(object=human_data,assay = 'RNA',
# cluster_order = unique(human_data$celltype),
genes = markers_plot, bar = c("celltype",'group','S.Score'),
cols_anno = list(celltype = setNames(c("#7A989A", "#849271", "#CF9546", "#C67052", "#C1AE8D"),unique(human_data$celltype)),
group = setNames(c("royalblue","indianred"),unique(human_data$group)),
S.Score = colorRamp2(c(min(human_data$S.Score),max(human_data$S.Score)), c('#1A5592',"#B83D3D"))))
#split
ks_single_marker_heatmap(object=human_data,assay = 'RNA',
# cluster_order = unique(human_data$celltype),
genes = markers_plot, bar = c("celltype",'group','S.Score'),
column_gap=1,
cols_anno = list(celltype = setNames(c("#7A989A", "#849271", "#CF9546", "#C67052", "#C1AE8D"),unique(human_data$celltype)),
group = setNames(c("royalblue","indianred"),unique(human_data$group)),
S.Score = colorRamp2(c(min(human_data$S.Score),max(human_data$S.Score)), c('#1A5592',"#B83D3D"))))
关注我们获取精彩内容:
关注不迷路:扫描下面二维码关注公众号!
B站视频号链接:https://space.bilibili.com/471040659?spm_id_from=333.1007.0.0
关注 KS科研分享与服务,
认清正版优质内容和服务!
优质内容持续输出,物超所值!
合作联系:ks_account@163.com