Author Published December 17, 2025 引言 本节来通过nature aging上的一篇论文来绘制一类常见的网络图,数据结构非常简单。论文提供了对应的数据小编结合论文介绍来进行代码编写,结果与原文有所不同。

个人观点仅供参考,更多详细介绍请查看论文信息 Integrating polygenic signals and single-cell multiomics identifies cell-type-specific regulomes critical for immune- and aging-related diseases Ma, Y., Yao, Y., Zhou, Y. et al. Integrating polygenic signals and single-cell multiomics identifies cell-type-specific regulomes critical for immune- and aging-related diseases. Nat Aging (2025). https://doi.org/10.1038/s43587-025-01027-5 结果图 加载R包 library (readxl) library (tidyverse) library (ggraph) library (igraph) sessionInfo R version 4.5.0 (2025-04-11) Platform: aarch64-apple-darwin20 Running under: macOS 26.1 Matrix products: default BLAS: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRblas.0.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.1 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] igraph_2.2.1 ggraph_2.2.2 lubridate_1.9.4 forcats_1.0.1 [5] stringr_1.6.0 dplyr_1.1.4 purrr_1.2.0 readr_2.1.6 [9] tidyr_1.3.1 tibble_3.3.0 ggplot2_4.0.1 tidyverse_2.0.0 [13] readxl_1.4.5 loaded via a namespace (and not attached): [1] viridis_0.6.5 generics_0.1.4 stringi_1.8.7 hms_1.1.4 [5] digest_0.6.39 magrittr_2.0.4 evaluate_1.0.5 grid_4.5.0 [9] timechange_0.3.0 RColorBrewer_1.1-3 fastmap_1.2.0 cellranger_1.1.0 [13] jsonlite_2.0.0 ggrepel_0.9.6 gridExtra_2.3 viridisLite_0.4.2 [17] scales_1.4.0 tweenr_2.0.3 cli_3.6.5 graphlayouts_1.2.2 [21] rlang_1.1.6 polyclip_1.10-7 tidygraph_1.3.1 cachem_1.1.0 [25] withr_3.0.2 yaml_2.3.12 tools_4.5.0 tzdb_0.5.0 [29] memoise_2.0.1 vctrs_0.6.5 R6_2.6.1 lifecycle_1.0.4 [33] htmlwidgets_1.6.4 MASS_7.3-65 pkgconfig_2.0.3 pillar_1.11.1 [37] gtable_0.3.6 glue_1.8.0 Rcpp_1.1.0 ggforce_0.5.0 [41] xfun_0.54 tidyselect_1.2.1 rstudioapi_0.17.1 knitr_1.50 [45] dichromat_2.0-0.1 farver_2.1.2 htmltools_0.5.9 rmarkdown_2.30 [49] compiler_4.5.0 S7_0.2.1 数据读取 df <- read_excel ( "43587_2025_1027_MOESM9_ESM.xlsx" , sheet = 4 ) %>% select ( 1 , 3 ) %>% filter (TF != 0 ) df # A tibble: 68 × 2 TF Target <chr> <chr> 1 FOXP2 PLXNA4 2 FOXP2 RUNX1T1 3 FOXP2 SCN2A 4 FOXP2 SOX6 5 FOXP2 THSD7A 6 FOXP2 ZFHX3 7 FOXP2 rs8180817(6.0e-21) 8 FOXP2 rs1476535(3.0e-26) 9 FOXP2 rs9969232(7.371e-11) 10 FOXP2 rs12705966(1.265e-10) # ℹ 58 more rows 数据构建 # 定义gwas基因 gwas_genes <- c ( "PLXNA4" , "RUNX1T1" , "SOX6" , "SCN2A" , "THSD7A" , "ZFHX3" ) # 构建节点文件 nodes <- tibble ( name = unique ( c (df $ TF, df $ Target))) %>% mutate ( node_type = case_when ( grepl ( "^rs" , name) ~ "SNP" , name == "FOXP2" ~ "TF" , name %in% c ( "ASD" , "ADHD" , "SCZ" , "MDD" , "BIP" ) ~ "Disease" , name %in% gwas_genes ~ "GWAS_Gene" ), node_type = factor ( node_type, levels = c ( "TF" , "Disease" , "GWAS_Gene" , "SNP" ))) # 格式转换 g <- graph_from_data_frame ( d = df, vertices = nodes, directed = FALSE ) ggraph绘图 set.seed ( 123 ) ggraph (g, layout = "fr" ) + # 定义边属性 geom_edge_link ( colour = "grey75" , width = 1.5 ) + # 定义节点属性 geom_node_point ( aes ( size = node_type, color = node_type, shape = node_type)) + # 添加文本 geom_node_text ( aes ( label = name), repel = TRUE , size = 3 , color= "black" ) + scale_color_manual ( values = c ( TF= " , Disease = " , GWAS_Gene= " , SNP= " )) + scale_size_manual ( values = c ( TF= 7 , Disease = 7 , GWAS_Gene= 7 , SNP= 7 )) + scale_shape_manual ( values = c ( TF= 17 , # 三角形 Disease = 18 , # 菱形 GWAS_Gene = 16 , SNP = 16 )) + theme_void + theme ( legend.position = "none" )