复现NC图表:二分图 (bipartite plot) 网络绘制(三种方法)-应用于细胞互作受配体展示-调控网络展示等等

如题,这个标题有点长,首先我们需要展示的图是bipartite plot,中文有叫二分图、连线图的,总之就是展示两组之间网络关系。可以应用的地方有很多,不只是我们介绍的互作关系、或者ligands-target。起源是一篇《nature communications》文章的图,它展示的是ligand于targets。原文提供了代码,可以学习!

image.png

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()

image.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值