代码
remove(list = ls())
setwd("D:/生信代码复现/R语言绘制网络组合图")
rm(list=ls())
library(tidyverse)
library(readxl)
library(tidygraph)
library(ggraph)
library(igraph)
library(cowplot)
library(ggnewscale)
source("layout_function.R")
source("combine_plot.R")
nodes<-readxl::read_xlsx(path="nodes.xlsx")
edges<-readxl::read_xlsx(path="edges.xlsx")
ppi<-readxl::read_xlsx(path="ppi.xlsx")
graph<-as_tbl_graph(ppi)%>%
tidygraph::mutate(Popularity=centrality_degree(mode='out'))%>%
tidygraph::left_join(nodes,by=c("name"="name"))
graph<-as_tbl_graph(ppi)%>%
tidygraph::mutate(Popularity=centrality_degree(mode='out'))%>%
tidygraph::left_join(nodes,by=c("name"="name"))
ly4<-layout_function(graph)
p_ppi<-ggraph(ly4)+
geom_edge_diagonal(aes(color=type))+
geom_node_point(aes(size=Popularity,color=type),alpha=1)+
geom_node_text(data=ly4%>%
tidygraph::filter(name%in%c("Cis","Ctrl")),
aes(label=name),
size=5,
color="#ffffff")+
scale_size(range=c(3,15))+
coord_fixed()+
theme_void()+
theme(legend.position="none")
nodes <- readxl::read_xlsx("nodes.xlsx")
data_ex <- nodes %>%
mutate(
id = row_number(),
data1 = sample(letters[1:5], n(), replace = TRUE),
data2 = runif(n(), min = 0, max = 20),
data3 = runif(n(), min = 0, max = 16),
data4 = runif(n(), min = 0, max = 30)
)
p2<-ggplot(data=data_ex)+
geom_tile(aes(x=id,y=1,fill=data1),height=0.2)+
scale_fill_manual(values=c('#8dd3c7','#ffffb3','#bebada','#fb8072','#80b1d3'),na.value="transparent")+
new_scale_fill()+
geom_tile(aes(x=id,y=1.25,fill=data2),height=0.2)+
scale_fill_gradient(low="#fcc5c0",high="#dd3497",na.value="transparent")+
new_scale_fill()+
geom_tile(aes(x=id,y=1.5,fill=data3),height=0.2)+
scale_fill_gradient(low="#dadaeb",high="#807dba",na.value="transparent")+
coord_polar(
start=1.17*pi
)+
scale_y_continuous(
limits=c(-1,2.5)
)+
theme_void()
p2
ggsave(filename = "Output/p2_plot.png",
plot = p2,
width = 10,
height = 10,
dpi = 300)
data_ex_add_angle<-data_ex%>%
dplyr::mutate(angle=90-360*(id-0.5)/nrow(.)+(1.17*pi))%>%
dplyr::mutate(hjust=ifelse(angle<-90,0,1))%>%
dplyr::mutate(angle=ifelse(angle<-90,angle+150,angle-25))
p3<-ggplot(data=data_ex_add_angle)+
geom_bar(aes(x=id,y=data4),stat="identity",fill="#d9d9d9")+
geom_text(data=data_ex_add_angle%>%dplyr::filter(!name%in%c("Cis","Ctrl")),
aes(x=id,y=data4+1,label=name,hjust=hjust),
angle=data_ex_add_angle%>%dplyr::filter(!name%in%c("Cis","Ctrl"))%>%pull(angle))+
coord_polar(
start=1.17*pi
)+
scale_y_continuous(
limits=c(-50,30)
)+
theme_void()
p3
p_combine<-combine_plot(p2,p_ppi,p3)
p_combine
ggsave(filename="Output/p_combine.pdf",
height=12,
width=12)
