-
Notifications
You must be signed in to change notification settings - Fork 1
/
bipartite_graphs_007.R
105 lines (89 loc) · 4.89 KB
/
bipartite_graphs_007.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Auxiliar script to create a bipartite graph in screen
library(kcorebip)
library(igraph)
giant.component <- function(graph) {
cl <- clusters(graph)
induced.subgraph(graph, which(cl$membership == which.max(cl$csize)))}
plot_bipartite <- function(bg, aspect_ratio = 9/35, vframecolor = "grey70", vlabelcex = 4,
vsize = 4, vcolor = c("cadetblue1","pink2"), labelcolor = c("blue","red"),
framedisp = FALSE, color_link = "grey50", vertical = FALSE, nname = "")
{
l <- layout.bipartite(bg)
if (vertical)
la <- l[, c(2,1)]
else
la <- l
png(paste0("datawip/",nname,".png"), height=600, width=1800)
#functions to plot your graph
plot.igraph(bg, layout= la,asp=aspect_ratio,vertex.frame.color=vframecolor,
vertex.label.cex=vlabelcex,vertex.label.color="black",vertex.label.family="Arial",
vertex.size=vsize, edge.color= color_link, frame = framedisp,
vertex.color=vcolor[V(bg)$type+1])
dev.off()
}
quita_vacios <- function(grafo,lgrados)
{
for (k in 1:length(lgrados))
{
if (lgrados[k] == 0){
grafo <- delete_vertices(grafo,names(lgrados[k]))
if ( length(grep("Pollinator",names(lgrados[k]) )) >0 )
num_species_b <<- num_species_b -1
else
num_species_a <<- num_species_a - 1
}
}
return(grafo)
}
redname <- "M_PL_007"
num_species_a <- 0
num_species_b <- 0
result_analysis <- analyze_network(paste0(redname,".csv"), directory = "data/", guild_a = "Plant", guild_b = "Pollinator", plot_graphs = FALSE)
original_GC <- length(V(giant.component(result_analysis$graph)))
print(paste("Original Network",redname))
print(paste("Giant Component",original_GC))
print(paste("Animal species",result_analysis$num_guild_b,"Vegetal species",result_analysis$num_guild_a))
bp <- get_bipartite(result_analysis$graph, plot_graphs = FALSE)
plot_bipartite(bp, aspect_ratio = 1/4,vlabelcex=2.0,vsize = 5, vframecolor = "transparent",
color_link = "grey20", vertical = FALSE, nname = redname)
redname <- "M_PL_007_kd"
result_analysis <- analyze_network(paste0(redname,".csv"), directory = "datawip/", guild_a = "Plant", guild_b = "Pollinator", plot_graphs = FALSE)
kd_GC <- length(V(giant.component(result_analysis$graph)))
result_analysis$degree <- igraph::degree(result_analysis$graph)
num_species_a <- result_analysis$num_guild_a
num_species_b <- result_analysis$num_guild_b
result_analysis$graph <- quita_vacios(result_analysis$graph, result_analysis$degree )
print("Network destroyed following kdegree")
print(paste("Giant Component",kd_GC))
print(paste("Animal species",num_species_b,"Vegetal species",num_species_a))
bp <- get_bipartite(result_analysis$graph, plot_graphs = FALSE)
plot_bipartite(bp, aspect_ratio = 1/4,vlabelcex=2.0,vsize = 5, vframecolor = "transparent",
color_link = "grey20", vertical = FALSE, nname = redname)
redname <- "M_PL_007_mr"
result_analysis <- analyze_network(paste0(redname,".csv"), directory = "datawip/", guild_a = "Plant", guild_b = "Pollinator", plot_graphs = FALSE)
result_analysis$degree <- igraph::degree(result_analysis$graph)
mr_GC <- length(V(giant.component(result_analysis$graph)))
num_species_a <- result_analysis$num_guild_a
num_species_b <- result_analysis$num_guild_b
result_analysis$graph <- quita_vacios(result_analysis$graph, result_analysis$degree )
print("Network destroyed following MusRank")
print(paste("Giant Component",mr_GC))
print(paste("Animal species",num_species_b,"Vegetal species",num_species_a))
bp <- get_bipartite(result_analysis$graph, plot_graphs = FALSE)
plot_bipartite(bp, aspect_ratio = 1/4,vlabelcex=2.0,vsize = 5, vframecolor = "transparent",
color_link = "grey20", vertical = FALSE, nname = redname)
ziggurat_graph("data/","M_PL_007.csv", height_box_y_expand = 1,
lsize_legend = 7, lsize_core_box = 6,corebox_border_size=1,
plotsdir = "datawip/",color_link = "slategray3", alpha_link = 0.5,
lsize_kcoremax = 6,lsize_zig = 5,lsize_kcore1 = 5,
displace_legend = c(-0.2,0.2),displace_outside_component = c(-1.1,0.6),print_to_file = TRUE)
ziggurat_graph("datawip/","M_PL_007_kd.csv", height_box_y_expand = 0.75,
lsize_legend = 7, lsize_core_box = 6,corebox_border_size=1,
plotsdir = "datawip/",color_link = "slategray3", alpha_link = 0.5,
lsize_kcoremax = 7,lsize_zig = 6,lsize_kcore1 = 5.5,
displace_legend = c(-0.2,0.4),displace_outside_component = c(-0.4,0.6),print_to_file = TRUE)
ziggurat_graph("datawip/","M_PL_007_mr.csv", height_box_y_expand = 1.55,
lsize_legend = 7, lsize_core_box = 6,corebox_border_size=1,aspect_ratio = 1.2,
plotsdir = "datawip/",color_link = "slategray3", alpha_link = 0.5,
lsize_kcoremax = 7,lsize_zig = 6,lsize_kcore1 = 5.5,
displace_legend = c(-0.2,0.2),displace_outside_component = c(-0.6,0.6),print_to_file = TRUE)