如題澎迎,這個標(biāo)題有點(diǎn)長,首先我們需要展示的圖是bipartite plot灵份,中文有叫二分圖哮洽、連線圖的,總之就是展示兩組之間網(wǎng)絡(luò)關(guān)系氛什》肆梗可以應(yīng)用的地方有很多,不只是我們介紹的互作關(guān)系贸铜、或者ligands-target蒿秦。起源是一篇《nature communications》文章的圖棍鳖,它展示的是ligand于targets渡处。原文提供了代碼祟辟,可以學(xué)習(xí)川尖!
(reference:Gliovascular transcriptional perturbations in Alzheimer’s disease reveal molecular mechanisms of blood brain barrier dysfunction)
ggraph叮喳,首先相比于igraph馍悟,在很多設(shè)置上因?yàn)榕cggplot互通锣咒,所以會簡單很多,沒有那么復(fù)雜趣兄,可操作性更強(qiáng)艇潭。layout可以自己設(shè)定蹋凝,也可以參照上面的鳍寂!
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)
#構(gòu)建ggraph作圖數(shù)據(jù)
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()
#調(diào)整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) +#節(jié)點(diǎn)設(shè)置
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)+ #文字標(biāo)注
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()