You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于R语言igraph包绘制基因-细胞区室环形布线图的技术需求

使用igraph绘制环形包围式基因-细胞区室关联图

步骤1:标记顶点类型

先给图中顶点添加「细胞区室」和「基因」的分类属性。如果节点列表(NL)没有现成分类列,可手动区分:

# 若NL有type列直接提取细胞区室名称
compartment_nodes <- NL$name[NL$type == "compartment"]
# 若没有type列,可手动指定13个细胞区室名称:compartment_nodes <- c("区室1", "区室2", ..., "区室13")

# 为图顶点添加类型属性
V(g)$node_type <- ifelse(V(g)$name %in% compartment_nodes, "compartment", "gene")

步骤2:设置顶点样式

按需求定义顶点颜色,同时可调整顶点大小突出层级:

# 细胞区室设红色,基因设蓝色
V(g)$color <- ifelse(V(g)$node_type == "compartment", "red", "blue")
# 可选:让细胞区室顶点更大,增强区分度
V(g)$size <- ifelse(V(g)$node_type == "compartment", 10, 6)

步骤3:自定义环形包围布局

实现细胞区室在外围环形、基因在内部的布局:

# 生成细胞区室的环形布局
comp_layout <- layout_in_circle(g, v = which(V(g)$node_type == "compartment"))
# 生成基因的内部随机布局,并缩放至环形内部
gene_layout <- layout_randomly(g, v = which(V(g)$node_type == "gene"))
gene_layout <- gene_layout * 0.5 # 缩放比例可根据视觉效果调整

# 合并布局:按顶点顺序替换对应坐标
full_layout <- layout_randomly(g) # 初始化布局模板
full_layout[which(V(g)$node_type == "compartment"), ] <- comp_layout
full_layout[which(V(g)$node_type == "gene"), ] <- gene_layout

# 标准化布局,确保整体显示范围协调
full_layout <- layout.norm(full_layout, xmin = -1, xmax = 1, ymin = -1, ymax = 1)

步骤4:绘制最终图形

调用绘图函数,传入自定义布局并优化显示参数:

plot(g,
     layout = full_layout,
     vertex.label.cex = 0.7, # 调整标签字号
     vertex.label.color = "black",
     edge.color = "gray", # 灰色边避免干扰顶点
     edge.width = 1,
     main = "基因-细胞区室关联图"
)

补充说明

  • 若图中存在同类型顶点间的冗余边,可通过E(g)[V(g)$node_type == V(g)$node_type] <- NULL删除。
  • 内部基因布局的缩放比例可根据实际显示效果微调,确保基因顶点在环形内部分布合理。

内容的提问来源于stack exchange,提问作者David TT

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 11:26:12