在模仿中精进数据可视化_使用circlize绘制相关性圈图
❝今天是
叶师兄
、老叶
、叶桑
、比我还卷的卷王
、好师兄
、爱撒娇的男人
、全篇都是美图的技术型师兄
、大半夜一点半还在敲代码的师兄
、承诺过未来带我飞的师兄
的
激情投稿!
❝
在模仿中精进数据可视化
该系列推文中,我们将从各大顶级学术期刊的Figure
入手,
解读文章的绘图思路,
模仿文章的作图风格,
构建适宜的绘图数据,
并且将代码应用到自己的实际论文中。
绘图缘由:小伙伴们总会展示出一些非常好看且精美的图片。我大概率会去学习和复现一下。其实每个人的时间和精力都非常有限和异常宝贵的。之所以我会去做,主要有以下原因:
图片非常好看,我自己看着也手痒痒 图片我自己在Paper也用的上,储备着留着用 保持了持续学习的状态
叶师兄
绘制的circlize
版本的相关性图
直接上代码:
加载R
包
rm(list = ls())
####----load R Package----####
library(tidyverse)
library(circlize)
library(statnet)
library(readxl)
library(RColorBrewer)
加载数据
####----load Data----####
ASV_B <- read_xlsx(path = "./Input/ASV_B.xlsx", col_names = T) %>%
column_to_rownames(var='ASV') %>%
as.data.frame()
ASV_B <- ASV_B %>%
rownames_to_column(var = 'ASV') %>%
pivot_longer(-ASV, names_to = 'sample', values_to = 'value')
grid_col <- c(setNames(rep("grey",16), ASV_B$sample %>% unique()),
setNames(brewer.pal(n = 9, name = "Paired"),
ASV_B$ASV %>% unique()))
开始绘图
####----Plot----####
pdf(file = "Output/P.pdf",
height = 18,
width = 25)
circos.par(start.degree = 90, "clock.wise" = T)
chordDiagram(ASV_B,
grid.col = grid_col,#颜色
annotationTrack = "grid",
transparency = 0.8,#透明度
link.lwd = 0.00001,#线条宽度
link.lty = 1, # 线路类型
link.border = 0,#边框颜色
directional = -1,#表示线条的方向,0代表没有方向,1代表正向,-1代表反向,2代表双向
diffHeight = mm_h(10),#外圈和中间连线的间隔
direction.type = c("diffHeight","arrows"), #线条是否带有箭头
link.arr.type = "big.arrow",#箭头类型
annotationTrackHeight = c(0.04, 0.1), #网格高度
target.prop.height = mm_h(30)
)
circos.track(track.index = 1,
panel.fun = function(x, y) {
circos.text(CELL_META$xcenter,
CELL_META$ylim[2]-1,
CELL_META$sector.index,
facing = "clockwise",
niceFacing = T,
adj = c(-0.5, 0.5),
cex = 1.25)
circos.axis(h = "top",
labels.cex = 1,
major.tick.length = mm_y(2),
labels.niceFacing = F,
labels.pos.adjust =F)},
bg.border = NA)
legend(x=1.2,y=0.5,
title="Species",title.adj=0.3,
bty='n',
legend=names(grid_col)[17:26], #设置图例边框y/n
pch=c(16),# 16圆,24三角
col=grid_col[17:26],
cex=2.5,
pt.cex=5,
ncol = 1,
xpd=T)
circos.clear()
dev.off()
版本信息
####----sessionInfo----####
R version 4.3.0 (2023-04-21)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS 15.1.1
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: Asia/Shanghai
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RColorBrewer_1.1-3 colorspace_2.1-1 readxl_1.4.3
[4] statnet_2019.6 tsna_0.3.5 sna_2.7-1
[7] statnet.common_4.9.0 ergm.count_4.1.1 tergm_4.2.0
[10] networkDynamic_0.11.3 ergm_4.5.0 network_1.18.1
[13] circlize_0.4.15 lubridate_1.9.3 forcats_1.0.0
[16] stringr_1.5.1 dplyr_1.1.4 purrr_1.0.2
[19] readr_2.1.5 tidyr_1.3.1 tibble_3.2.1
[22] ggplot2_3.5.1 tidyverse_2.0.0
loaded via a namespace (and not attached):
[1] gtable_0.3.5 networkLite_1.0.5
[3] shape_1.4.6 GlobalOptions_0.1.2
[5] ergm.multi_0.2.0 rle_0.9.2
[7] lattice_0.22-5 tzdb_0.4.0
[9] vctrs_0.6.5 tools_4.3.0
[11] Rdpack_2.6 generics_0.1.3
[13] parallel_4.3.0 fansi_1.0.6
[15] DEoptimR_1.1-3 pkgconfig_2.0.3
[17] Matrix_1.6-5 lifecycle_1.0.4
[19] compiler_4.3.0 munsell_0.5.1
[21] pillar_1.9.0 MASS_7.3-60
[23] cachem_1.1.0 trust_0.1-8
[25] nlme_3.1-163 robustbase_0.99-0
[27] tidyselect_1.2.1 stringi_1.8.3
[29] fastmap_1.2.0 grid_4.3.0
[31] cli_3.6.3 magrittr_2.0.3
[33] utf8_1.2.4 withr_3.0.1
[35] scales_1.3.0 timechange_0.2.0
[37] cellranger_1.1.0 hms_1.1.3
[39] coda_0.19-4 memoise_2.0.1
[41] lpSolveAPI_5.5.2.0-17.10 rbibutils_2.2.16
[43] rlang_1.1.4 glue_1.8.0
[45] rstudioapi_0.15.0 R6_2.5.1
历史绘图合集
公众号推文一览
进化树合集
环状图
散点图
基因家族合集
换一个排布方式:
首先查看基础版热图:
然后再看进阶版热图:
基因组共线性
WGCNA ggplot2版本
其他科研绘图
合作、联系和交流
有很多小伙伴在后台私信作者,非常抱歉,我经常看不到导致错过,请添加下面的微信联系作者,一起交流数据分析和可视化。