我尝试创建网络布局的图片(最终说明网络如何随着时间的推移而改变)。我的apprach是创建一个最终网络(参见net0),然后逐个节点(及其边缘)删除。
如何确保图表的布局保持不变? (并且不会重新缩放!) 最终目标:具有不同节点数但具有与最终图net0
中定义的完全相同的布局的图的序列我的方法:
代码:
library(igraph)
data <- structure(c( "A","A","D","D","F","G","B","B","D","G","D","G","G","F","H","H","G","D","I","I"),.Dim = c(10L, 2L), .Dimnames = list(NULL,c("source","target")))
layout <-structure(c(-3.26,-5.50,-2.33,0.48,-3.37,-7.44,-10.00,-8.32,-5.09,-5.19,-3.15,-2.22,-1.9,-4.00),.Dim = c(7L, 2L), .Dimnames = list(NULL, c("coordinate.1", "coordinate.2")))
net0 <- graph.edgelist(data, directed=FALSE)
par(pin=c(9, 4.7), mai=c(0.5, 0.1, 0.15, 0.1))
plot(net0, layout=layout)
net <- delete.edges(net0, c(9,10))
net <- delete.vertices(net, c("I"))
plot(net, layout=layout)
net <- delete.edges(net0, c(9,10))
net <- delete.vertices(net, c("I"))
plot(net, layout=layout[1:6,])
答案 0 :(得分:7)
将布局添加为x
和y
顶点属性:
V(net0)$x <- layout[,1]
V(net0)$y <- layout[,2]
这些内容由plot()
自动使用,请参阅默认布局?layout.auto
。