R实战 | 环状热图(circos)

简介: R实战 | 环状热图(circos)

circular_heatmap

「之前画过的热图:」

  1. 跟着 Cell 学作图 | 复杂热图(ComplexHeatmap)
  2. 跟着 Nature 学作图 | 复杂热图2.0(连续+分类变量)
  3. R实战 | 复杂热图3.0(ComplexHeatmap)

本期图片

将上一期的热图掰弯,并随机给differetially methylated regions (DMRs)加个几个相互作用。


绘制

示例数据

rm(list = ls())
# devtools::install_github("jokergoo/Complexheatmap")
library(ComplexHeatmap)
library(circlize)
library(RColorBrewer)
# 载入示例数据
res_list = readRDS("meth.rds")
str(res_list)
type = res_list$type
mat_meth = res_list$mat_meth
mat_expr = res_list$mat_expr
direction = res_list$direction
cor_pvalue = res_list$cor_pvalue
gene_type = res_list$gene_type
anno_gene = res_list$anno_gene
dist = res_list$dist
anno_enhancer = res_list$anno_enhancer
source("random_matrices.R")

绘制

set.seed(123)
km = kmeans(mat_meth, centers = 5)$cluster
# 一圈一圈轨迹叠加
col_meth = colorRamp2(c(0, 0.5, 1), c("blue", "white", "red"))
circos.heatmap(mat_meth, split = km, col = col_meth, track.height = 0.12)
col_direction = c("hyper" = "red", "hypo" = "blue")
circos.heatmap(direction, col = col_direction, track.height = 0.01)
col_expr = colorRamp2(c(-2, 0, 2), c("green", "white", "red"))
circos.heatmap(mat_expr, col = col_expr, track.height = 0.12)
col_pvalue = colorRamp2(c(0, 2, 4), c("white", "white", "red"))
circos.heatmap(cor_pvalue, col = col_pvalue, track.height = 0.01)
col_gene_type = structure(brewer.pal(length(unique(gene_type)), "Set3"), names = unique(gene_type))
circos.heatmap(gene_type, col = col_gene_type, track.height = 0.01)
col_anno_gene = structure(brewer.pal(length(unique(anno_gene)), "Set1"), names = unique(anno_gene))
circos.heatmap(anno_gene, col = col_anno_gene, track.height = 0.01) 
col_dist = colorRamp2(c(0, 10000), c("black", "white"))
circos.heatmap(dist, col = col_dist, track.height = 0.01)
col_enhancer = colorRamp2(c(0, 1), c("white", "orange"))
circos.heatmap(anno_enhancer, col = col_enhancer, track.height = 0.03)
circos.clear()
df_link = data.frame(
  from_index = sample(nrow(mat_meth), 20),
  to_index = sample(nrow(mat_meth), 20)
)
circlize_plot = function() {
  circos.heatmap(mat_meth, split = km, col = col_meth, track.height = 0.12)
  circos.heatmap(direction, col = col_direction, track.height = 0.01)
  circos.heatmap(mat_expr, col = col_expr, track.height = 0.12)
  circos.heatmap(cor_pvalue, col = col_pvalue, track.height = 0.01)
  circos.heatmap(gene_type, col = col_gene_type, track.height = 0.01)
  circos.heatmap(anno_gene, col = col_anno_gene, track.height = 0.01) 
  circos.heatmap(dist, col = col_dist, track.height = 0.01)
  circos.heatmap(anno_enhancer, col = col_enhancer, track.height = 0.03)
  for(i in seq_len(nrow(df_link))) {
    circos.heatmap.link(df_link$from_index[i],
                        df_link$to_index[i],
                        col = rand_color(1))
  }
  circos.clear()
}
lgd_meth = Legend(title = "Methylation", col_fun = col_meth)
lgd_direction = Legend(title = "Direction", at = names(col_direction), 
                       legend_gp = gpar(fill = col_direction))
lgd_expr = Legend(title = "Expression", col_fun = col_expr)
lgd_pvalue = Legend(title = "P-value", col_fun = col_pvalue, at = c(0, 2, 4), 
                    labels = c(1, 0.01, 0.0001))
lgd_gene_type = Legend(title = "Gene type", at = names(col_gene_type), 
                       legend_gp = gpar(fill = col_gene_type))
lgd_anno_gene = Legend(title = "Gene anno", at = names(col_anno_gene), 
                       legend_gp = gpar(fill = col_anno_gene))
lgd_dist = Legend(title = "Dist to TSS", col_fun = col_dist, 
                  at = c(0, 5000, 10000), labels = c("0kb", "5kb", "10kb"))
lgd_enhancer = Legend(title = "Enhancer overlap", col_fun = col_enhancer, 
                      at = c(0, 0.25, 0.5, 0.75, 1), labels = c("0%", "25%", "50%", "75%", "100%"))
library(gridBase)
plot.new()
circle_size = unit(1, "snpc") # snpc unit gives you a square region
pushViewport(viewport(x = 0, y = 0.5, width = circle_size, height = circle_size,
                      just = c("left", "center")))
par(omi = gridOMI(), new = TRUE)
circlize_plot()
upViewport()
h = dev.size()[2]
lgd_list = packLegend(lgd_meth, lgd_direction, lgd_expr, lgd_pvalue, lgd_gene_type, 
                      lgd_anno_gene, lgd_dist, lgd_enhancer, max_height = unit(0.9*h, "inch"))
draw(lgd_list, x = circle_size, just = "left")

result

参考

  1. Supplementary S3. Correlations between methylation, expression and other genomic features (jokergoo.github.io)
  2. Chapter 6 The circos.heatmap() function | Circular Visualization in R (jokergoo.github.io)

往期

  1. CNS图表复现|生信分析|R绘图 资源分享&讨论群!
  2. 这图怎么画| 有点复杂的散点图
  3. 这图怎么画 | 相关分析棒棒糖图
  4. 组学生信| Front Immunol |基于血清蛋白质组早期诊断标志筛选的简单套路
  5. (免费教程+代码领取)|跟着Cell学作图系列合集
  6. Q&A | 如何在论文中画出漂亮的插图?
  7. 跟着 Cell 学作图 | 桑葚图(ggalluvial)
  8. R实战 | Lasso回归模型建立及变量筛选
  9. 跟着 NC 学作图 | 互作网络图进阶(蛋白+富集通路)(Cytoscape)
  10. R实战 | 给聚类加个圈圈(ggunchull)
  11. R实战 | NGS数据时间序列分析(maSigPro)
  12. 跟着 Cell 学作图 | 韦恩图(ggVennDiagram)


相关文章
|
物联网 测试技术 Android开发
蓝牙BLE传输性能及延迟分析
BLE传输性能主要受以下几个因素影响:操作类型,Connection Interval,每个Connection Event内发送的帧数、每一帧数据的长度。具体参见如下链接: https://en.wikipedia.
4375 0
|
存储 数据可视化 数据挖掘
R语言绘制圈图、环形热图可视化基因组实战:展示基因数据比较
R语言绘制圈图、环形热图可视化基因组实战:展示基因数据比较
|
机器学习/深度学习 人工智能 自然语言处理
企业内训|LLM大模型技术在金融领域的应用及实践-某商业银行分行IT团队
本企业培训是TsingtaoAI技术团队专们为某商业银行分行IT团队开发的LLM大模型技术课程。课程深入分析大模型在金融行业中的发展趋势、底层技术及应用场景,重点提升学员在大模型应用中的实际操作能力与业务场景适应力。通过对全球商用 LLM 产品及国内外技术生态的深度对比,学员将了解大模型在不同企业中的发展路径,掌握如 GPT 系列、Claude 系列、文心一言等大模型的前沿技术。针对金融行业的业务需求,学员将学会如何结合多模态技术改进用户体验、数据分析等服务流程,并掌握大模型训练与工具链的实操技术,尤其是模型的微调、迁移学习与压缩技术。
475 2
|
Linux
网络IO管理
网络IO管理
656 0
|
搜索推荐 Docker 容器
生信分析代码之前还好好的,怎么就报错了 Error in Ops. data. frame(guide_loc, panel_loc) :'==' only defined for equally-sized data frames
执行 `DimPlot` 函数时遇到错误 `;Error in Ops. data. frame(g guides_loc, panel_loc) : '==' only defined for equally-sized data frames`。解决方案和办法
2476 0
生信分析代码之前还好好的,怎么就报错了 Error in Ops. data. frame(guide_loc, panel_loc) :'==' only defined for equally-sized data frames
|
Web App开发 存储 数据可视化
VCF文件修改染色体格式的方法
VCF文件修改染色体格式的方法
|
开发者 Python
【Python】已解决:FutureWarning: The default value of regex will change from True to False in a future ver
【Python】已解决:FutureWarning: The default value of regex will change from True to False in a future ver
569 1
|
机器学习/深度学习 人工智能 算法
高性价比发文典范——101种机器学习算法组合革新骨肉瘤预后模型
随着高通量测序技术的飞速发展和多组学分析的广泛应用,科研人员在探索生物学奥秘时经常遇到一个令人又爱又恼的问题:如何从浩如烟海的数据中挖掘出潜在的疾病关联靶点?又如何构建一个全面而有效的诊断或预后模型?只有通过优雅的数据挖掘、精致的结果展示、深入的讨论分析,并且辅以充分的湿实验验证,我们才能锻造出一篇兼具深度与广度的“干湿结合”佳作。
1511 0
高性价比发文典范——101种机器学习算法组合革新骨肉瘤预后模型
|
存储 监控 安全
JVM内存问题之如何比较不同时间点的pmap输出以检查新增或变大的内存段
JVM内存问题之如何比较不同时间点的pmap输出以检查新增或变大的内存段
204 0
|
数据可视化
利用ggcor包绘制相关性组合图及环状热图
ggcor包最初是因为能快速实现19年Science一组合相关性图(上图所示)变得流行起来,除此该包对热图、热图等等的可视化都是很方便快捷的,除了之前介绍过的几种相关性图几种方式,此包也是个不错的选择,且具独特的风格(特别是组合相关性图、环形热图)。但是不知道因为何种原因此包在Github上消失了....,到作者(厚缊)个人博客上瞅了瞅发现关于包的参数介绍示例等也都没有了,在评论区里看到作者回答项目已不再提供任何代码和任何资料,需要的可以去国内的gitee和国外的github搜索看看有没有别人存的代码。
1243 0