我生成了一个无向加权网络图,如下所示:
但是,它看起来并不整洁,是否可以以圆形方式排列节点以使其看起来更整洁和清晰?还有什么方法可以增加图例的大小并使它显示在中央底部?
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')
答案 0 :(得分:3)
您可以通过构建自己的布局来实现。
首先要获得纯圆形的布局,您可以使用:
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"
为图例增加了一些额外的空间。但这仅给传奇留下了一点空间。另一种方法是在布局中的右下角为图例留出一些额外的空间 。然后,您可以将字体变大一些。
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")