复现NC图表:二分图(bipartiteplot)网络绘制(三种方法)-应用于细胞互作受配体展示-调控网络展示等
- 互联网
- 2025-09-21 01:15:01

如题,这个标题有点长,首先我们需要展示的图是bipartite plot,中文有叫二分图、连线图的,总之就是展示两组之间网络关系。可以应用的地方有很多,不只是我们介绍的互作关系、或者ligands-target。起源是一篇《nature communications》文章的图,它展示的是ligand于targets。原文提供了代码,可以学习!
image.png
(reference:Gliovascular transcriptional perturbations in Alzheimer’s disease reveal molecular mechanisms of blood brain barrier dysfunction) ggraph,首先相比于igraph,在很多设置上因为与ggplot互通,所以会简单很多,没有那么复杂,可操作性更强。layout可以自己设定,也可以参照上面的!
node_info <- rbind(data.frame(node = rownames(active_ligand_target_links), group="target"), data.frame(node = colnames(active_ligand_target_links), group="ligands")) no <- c(rep("no", 20), sample(c('up','down'), size = nrow(node_info)-20, replace = TRUE)) node_info$reg <- sample(no, size =nrow(node_info), replace = TRUE) #构建ggraph作图数据 df_graph <- as_tbl_graph(as.matrix(active_ligand_target_links)) %>% mutate(group=node_info$group, #添加分组信息 reg = node_info$reg) #plot # sugiyama ggraph(df_graph, layout = 'igraph', algorithm='bipartite') + geom_edge_link(aes(colour=weight), edge_width =1)+ scale_edge_color_gradientn(colours = c("grey80","grey50","grey30","black"))+ geom_node_point(aes(fill=reg, filter= group =='ligands'), size=2,shape=21) + geom_node_point(aes(fill=reg, filter= group =='target'), size=2,shape=23)+ scale_fill_manual(values = c("#E4502E","#69B7CE","black"), breaks = c("up",'down',"no"), labels = c("up",'down',"no"))+ geom_node_text(aes(filter= group =='ligands', label = name), fontface = "italic", hjust=1.1)+ geom_node_text(aes(filter= group =='target', label = name), fontface = "italic", hjust=-0.1)+ coord_flip()+ theme_minimal() + scale_y_discrete(expand = c(0.2,0.2))+ ggraph::th_no_axes() #调整layout LO1 <- layout_as_bipartite(df_graph, maxiter=0); re_pos <- c(seq(from = 0.5, by = 1, length.out = length(LO1[which(LO1[,2]==1)])), seq(from = 0.5, by = 1.1, length.out = length(LO1[which(LO1[,2]==0)]))) LO1[,1] <- re_pos ggraph(df_graph, layout = LO1) + geom_edge_link(aes(colour=weight), edge_width =1)+ #连线 scale_edge_color_gradientn(colours = c(alpha("grey90",0.5), alpha("grey60",0.5), alpha("grey30",0.5),"black"))+#连线颜色 geom_node_point(aes(fill=reg, filter= group =='ligands'), size=2,shape=21) +#节点设置 geom_node_point(aes(fill=reg, filter= group =='target'), size=2,shape=23)+ scale_fill_manual(values = c("#E4502E","#69B7CE","black"), breaks = c("up",'down',"no"), labels = c("up",'down',"no"))+ geom_node_text(aes(filter= group =='ligands', label = name), fontface = "italic", hjust=1.1)+ #文字标注 geom_node_text(aes(filter= group =='target', label = name), fontface = "italic", hjust=-0.1)+ coord_flip()+ theme_minimal() + scale_y_discrete(expand = c(0.2,0.2))+ ggraph::th_no_axes()复现NC图表:二分图(bipartiteplot)网络绘制(三种方法)-应用于细胞互作受配体展示-调控网络展示等由讯客互联互联网栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“复现NC图表:二分图(bipartiteplot)网络绘制(三种方法)-应用于细胞互作受配体展示-调控网络展示等”