自定义 igraph
Customizing igraph
我生成了一个无向加权网络图,如下所示:
但是看起来不太整齐,能否将节点做成圆形排列,看起来更整齐清晰?还有什么方法可以增加图例的大小并使其出现在中心底部?
这个的R代码如下:
library(igraph)
setwd('C:/Users/malsa876/Desktop/RTest')
a <-c(33,6,5,5,6,1,2,1,0,4,2,4,1,2,2,0,0,0,5,0,0,0,2,1,0,0,2,1,0,2,0,0,0,0,0,0,1,0,0,1,0,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
class(a)
dim(a) <- c(8,8)
#l <-layout.reingold.tilford(g)
a
# create igraph object.
g <- graph.adjacency(a, mode="undirected", weighted=TRUE)
V(g)$label.cex <- 0.5
V(g)$name<-c("OD", "ACC", "SI", "T", "RD","SCA", "RU", "CC")
plot(g,main = 'Network Analysis of Interlinked Dimensions',edge.label=round(E(g)$weight, 3),vertex.label = V(g)$name)
legend("bottomright", c("OD - Operational Demonstration", "ACC - Accuracy", "SI - Stakeholders Interests", "T - Time", "RD - Requirements Dependency","SCA - Scalability","RU - Requirements Updates","CC - Computational Complexity"),cex=0.5,title = 'Legend')
V(g)$label.cex <- 0.5
V(g)$name<-c("OD", "ACC", "SI", "T", "RD","SCA", "RU", "CC")
d<-V(g)$label
E(g)$width <- E(g)$weight + min(E(g)$weight) + 1 # offset=1
plot(g,main = 'Network Analysis of Parameters',edge.label=round(E(g)$weight, 3),vertex.label = V(g)$name)
legend("bottomright", c("OD - Operational Demonstration", "ACC - Accuracy", "SI - Stakeholders Interests", "T - Time", "RD - Requirements Dependency","SCA - Scalability","RU - Requirements Updates","CC - Computational Complexity"),cex=0.5,title = 'Legend')
您可以通过构建自己的布局来做到这一点。
首先要获得纯圆形布局,您可以使用:
LO1 = matrix(c(cos((0:7)*2*pi/8), sin((0:7)*2*pi/8)),ncol=2)
plot(g,main = 'Network Analysis of Parameters', layout=LO1)
edge.label=round(E(g)$weight, 3),vertex.label = V(g)$name)
legend("bottomright", c("OD - Operational Demonstration",
"ACC - Accuracy", "SI - Stakeholders Interests",
"T - Time", "RD - Requirements Dependency",
"SCA - Scalability","RU - Requirements Updates",
"CC - Computational Complexity"),cex=0.5,title = 'Legend',
bty="n")
请注意,我使用 bty="n"
为图例留出一点额外空间。但这只为传奇留下了一点空间。另一种方法是在布局 中为右下方的图例保留一些额外的 space 。然后你可以把字体调大一点。
LO2 = matrix(c(cos((0:7)*2*pi/9), sin((0:7)*2*pi/9)),ncol=2)
plot(g,main = 'Network Analysis of Parameters', layout=LO2,
edge.label=round(E(g)$weight, 3),vertex.label = V(g)$name)
legend("bottomright", c("OD - Operational Demonstration",
"ACC - Accuracy", "SI - Stakeholders Interests",
"T - Time", "RD - Requirements Dependency",
"SCA - Scalability","RU - Requirements Updates",
"CC - Computational Complexity"),cex=0.7,title = 'Legend',
bty="n")
我生成了一个无向加权网络图,如下所示:
但是看起来不太整齐,能否将节点做成圆形排列,看起来更整齐清晰?还有什么方法可以增加图例的大小并使其出现在中心底部?
这个的R代码如下:
library(igraph)
setwd('C:/Users/malsa876/Desktop/RTest')
a <-c(33,6,5,5,6,1,2,1,0,4,2,4,1,2,2,0,0,0,5,0,0,0,2,1,0,0,2,1,0,2,0,0,0,0,0,0,1,0,0,1,0,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
class(a)
dim(a) <- c(8,8)
#l <-layout.reingold.tilford(g)
a
# create igraph object.
g <- graph.adjacency(a, mode="undirected", weighted=TRUE)
V(g)$label.cex <- 0.5
V(g)$name<-c("OD", "ACC", "SI", "T", "RD","SCA", "RU", "CC")
plot(g,main = 'Network Analysis of Interlinked Dimensions',edge.label=round(E(g)$weight, 3),vertex.label = V(g)$name)
legend("bottomright", c("OD - Operational Demonstration", "ACC - Accuracy", "SI - Stakeholders Interests", "T - Time", "RD - Requirements Dependency","SCA - Scalability","RU - Requirements Updates","CC - Computational Complexity"),cex=0.5,title = 'Legend')
V(g)$label.cex <- 0.5
V(g)$name<-c("OD", "ACC", "SI", "T", "RD","SCA", "RU", "CC")
d<-V(g)$label
E(g)$width <- E(g)$weight + min(E(g)$weight) + 1 # offset=1
plot(g,main = 'Network Analysis of Parameters',edge.label=round(E(g)$weight, 3),vertex.label = V(g)$name)
legend("bottomright", c("OD - Operational Demonstration", "ACC - Accuracy", "SI - Stakeholders Interests", "T - Time", "RD - Requirements Dependency","SCA - Scalability","RU - Requirements Updates","CC - Computational Complexity"),cex=0.5,title = 'Legend')
您可以通过构建自己的布局来做到这一点。
首先要获得纯圆形布局,您可以使用:
LO1 = matrix(c(cos((0:7)*2*pi/8), sin((0:7)*2*pi/8)),ncol=2)
plot(g,main = 'Network Analysis of Parameters', layout=LO1)
edge.label=round(E(g)$weight, 3),vertex.label = V(g)$name)
legend("bottomright", c("OD - Operational Demonstration",
"ACC - Accuracy", "SI - Stakeholders Interests",
"T - Time", "RD - Requirements Dependency",
"SCA - Scalability","RU - Requirements Updates",
"CC - Computational Complexity"),cex=0.5,title = 'Legend',
bty="n")
请注意,我使用 bty="n"
为图例留出一点额外空间。但这只为传奇留下了一点空间。另一种方法是在布局 中为右下方的图例保留一些额外的 space 。然后你可以把字体调大一点。
LO2 = matrix(c(cos((0:7)*2*pi/9), sin((0:7)*2*pi/9)),ncol=2)
plot(g,main = 'Network Analysis of Parameters', layout=LO2,
edge.label=round(E(g)$weight, 3),vertex.label = V(g)$name)
legend("bottomright", c("OD - Operational Demonstration",
"ACC - Accuracy", "SI - Stakeholders Interests",
"T - Time", "RD - Requirements Dependency",
"SCA - Scalability","RU - Requirements Updates",
"CC - Computational Complexity"),cex=0.7,title = 'Legend',
bty="n")